locked
Async cancellation of RIA Services RRS feed

  • Question

  • Hello,

    I am trying to implemente cancellation handling on my Silverlight RIA Services calls.

    I am using this article as a reference, and the async calls are working fine so far.

    But, when I try to cancel a load operation for instance, the task wait does not returns. As I can see, the request was properly managed, since OperationExtensions calls tcs.TrySetCanceled(); witch returns true.

    Here is a snippet of my code:

     LoadOperation loadOp = this.ProjectsContext.Load<Projects>(ProjectsContext.GetProjectsQuery().OrderBy(project => project.date), LoadBehavior.RefreshCurrent, false);
                PendingOperations.Add(loadOp);
                await loadOp.AsTask();
                PendingOperations.Remove(loadOp);

    I put a breakpoint at the last line and it is not hit after the user request on the UI the cancelation of the operation, witch is made using the loadOP reference.

    Any toughts?

    Igor.


    .NET Software developer for industrial internet and automation system.

    Monday, January 5, 2015 4:54 PM

Answers

  • So I had a look at the decompiled RIA Services source and it seems like the cancel is client side only. No change to the server-side process is made.

    Basically when you run operation.Cancel(), it makes sure the operation can be canceled (operation.CanCancel), and then marks it as canceled, and triggers the completion action.

    This means that the server-side operation still continues, but nothing is done with the response client side when it completes

    Once the operation has completed, you'll need to check the operation.IsCanceled property to see if that operation was canceled. If so, just ignore the result.

    • Marked as answer by Jonny_D Wednesday, January 14, 2015 9:55 AM
    Monday, January 12, 2015 3:10 AM

All replies

  • Hi,


    It seems there is no way to cancel  LoadOperation on the Server.

    For more information,please check links below:

    https://social.msdn.microsoft.com/forums/silverlight/en-US/546231bd-0cd8-430e-b6bb-f1abf4c236f4/is-it-possible-to-cancel-a-loadoperation-on-the-server

    http://stackoverflow.com/questions/10677776/how-to-cancel-a-ria-services-loadoperation


    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.




    Tuesday, January 6, 2015 5:38 AM
  • Hello Qimin,

    I want to cancel operations on the CLIENT side.

    So far I could manage the issue by catching TaskCanceledException:

    LoadOperation loadOp = this.myContext.Load<PieceGroup>(this.myContext.GetPieceGroupsForProjectQuery(projectid), LoadBehavior.RefreshCurrent, false); PendingOperations.Add(loadOp); try { await loadOp.AsTask(); if (loadOp.HasError) { loadOp.MarkErrorAsHandled(); ErrorWindow.CreateNew(loadOp.Error.Message); return; } } catch (TaskCanceledException) { PendingOperations.Remove(loadOp);

    //perform cancelation stuff return; } PendingOperations.Remove(loadOp);

    My code still cancel the operation, but the cancelation handling is made on the related task. Not sure if this is the best approach.

    Igor.


    .NET Software developer for industrial internet and automation system.

    Tuesday, January 6, 2015 8:28 AM
  • So I had a look at the decompiled RIA Services source and it seems like the cancel is client side only. No change to the server-side process is made.

    Basically when you run operation.Cancel(), it makes sure the operation can be canceled (operation.CanCancel), and then marks it as canceled, and triggers the completion action.

    This means that the server-side operation still continues, but nothing is done with the response client side when it completes

    Once the operation has completed, you'll need to check the operation.IsCanceled property to see if that operation was canceled. If so, just ignore the result.

    • Marked as answer by Jonny_D Wednesday, January 14, 2015 9:55 AM
    Monday, January 12, 2015 3:10 AM