New Posts New Posts RSS Feed: MarkErrorAsHandled() doesn't work on InvokeServerMethodOperation Coroutine
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

MarkErrorAsHandled() doesn't work on InvokeServerMethodOperation Coroutine

 Post Reply Post Reply
Author
JoeGershgorin View Drop Down
Newbie
Newbie


Joined: 24-Feb-2010
Location: USA
Posts: 14
Post Options Post Options   Quote JoeGershgorin Quote  Post ReplyReply Direct Link To This Post Topic: MarkErrorAsHandled() doesn't work on InvokeServerMethodOperation Coroutine
    Posted: 13-May-2011 at 12:58pm
Running DevForce 6.0.9 under Silverlight 4. I have a server side invoke method that looks like this:

public InvokeServerMethodOperation GetPasTimeSheetOperation(DateTime? dateTime)
{
    const string typeName = PASManagerServerInvokeConsts.TypeName;
    const string methodName = PASManagerServerInvokeConsts.MethodNames.GetTimeSheet;

    var pasImportRequest = new PASImportRequest { UserName = PASUserName, Password = PASPassword, WeekEnding = dateTime };

    return Manager.InvokeServerMethodAsync(
        typeName,
        methodName,
        null,
        null,
        pasImportRequest
        );
}
       

Which gets called in a co-routine like this:

var getPasTimeSheetOperation = _timeSheetRepository.GetPasTimeSheetOperation(_selectedDate);
             
yield return getPasTimeSheetOperation;            

if (getPasTimeSheetOperation.HasError)
{
    getPasTimeSheetOperation.MarkErrorAsHandled();
}

However if the server side method throws an exception it flow to the main application. The only way to prevent this is call the MarkErrorAsHandled() in the InvokeServerMethodAsync callback like this:

public InvokeServerMethodOperation GetPasTimeSheetOperation(DateTime? dateTime)
{
    const string typeName = PASManagerServerInvokeConsts.TypeName;
    const string methodName = PASManagerServerInvokeConsts.MethodNames.GetTimeSheet;

    var pasImportRequest = new PASImportRequest { UserName = PASUserName, Password = PASPassword, WeekEnding = dateTime };

    return Manager.InvokeServerMethodAsync(
        typeName,
        methodName,
        HandlerToEatErrors,
        null,
        pasImportRequest
        );
}

private void HandlerToEatErrors(InvokeServerMethodOperation op)
{
    op.MarkErrorAsHandled();           
}

This seems a little kludgy, is this a defect or am I doing something wrong?
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 13-May-2011 at 7:32pm
Hi Joe;

That is actually the correct operation. If you notice, if you don't handle the errors in the server side method, the following code will never be reached on the Coroutine call.

if (getPasTimeSheetOperation.HasError)
{
    getPasTimeSheetOperation.MarkErrorAsHandled();
}

This is because as soon as an async op failed, in this case, the getPasTimeSheetOperation, the Coroutine iterator block exits immediately. If you don't want to mark the errors as handled in the server side method, my other suggestion would be to handle them in the Coroutine completed event.

You can read Kim's response for further explanation on how Coroutine handles errors in this post.


Hope this helps.
Back to Top
JoeGershgorin View Drop Down
Newbie
Newbie


Joined: 24-Feb-2010
Location: USA
Posts: 14
Post Options Post Options   Quote JoeGershgorin Quote  Post ReplyReply Direct Link To This Post Posted: 14-May-2011 at 8:21pm
One of the nice things about co-routines is not having to manage events/callbacks in program flow. Sounds like the current iterator structure only handles successful program flow and I have to fallback to callbacks for error handling, thanks for the info.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 16-May-2011 at 11:47am
Yes, you have to handle the errors inside callbacks since we're working async but the callbacks can still be inside the coroutines iterator.

Please see this DRC write up for suggestions on how to handle async operation errors in coroutines.

Back to Top
JoeGershgorin View Drop Down
Newbie
Newbie


Joined: 24-Feb-2010
Location: USA
Posts: 14
Post Options Post Options   Quote JoeGershgorin Quote  Post ReplyReply Direct Link To This Post Posted: 16-May-2011 at 3:30pm
Thanks for the link, very informative.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down