Print Page | Close Window

MarkErrorAsHandled() doesn't work on InvokeServerMethodOperation Coroutine

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2677
Printed Date: 26-Jan-2026 at 2:50pm


Topic: MarkErrorAsHandled() doesn't work on InvokeServerMethodOperation Coroutine
Posted By: JoeGershgorin
Subject: MarkErrorAsHandled() doesn't work on InvokeServerMethodOperation Coroutine
Date 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?



Replies:
Posted By: DenisK
Date 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.

http://www.ideablade.com/forum/forum_posts.asp?TID=2565&PID=10206&title=coroutine-error-handling#10206 - http://www.ideablade.com/forum/forum_posts.asp?TID=2565&PID=10206&title=coroutine-error-handling#10206

Hope this helps.


Posted By: JoeGershgorin
Date 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.


Posted By: DenisK
Date 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.

http://drc.ideablade.com/xwiki/bin/view/Documentation/asynchronous-coroutine-errors - http://drc.ideablade.com/xwiki/bin/view/Documentation/asynchronous-coroutine-errors




Posted By: JoeGershgorin
Date Posted: 16-May-2011 at 3:30pm
Thanks for the link, very informative.



Print Page | Close Window