Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Cancel a RIA Services LoadOperation

I am using RIA services in a Silverlight project. I am using the LoadOperation class on the client side to load some data from the server.

In the process of loading that data the request might be superseded by a newer request for different data. This is based on multiple LoadOperations being made to the server, then the user clicking a cancel button.

If I take my LoadOperation and call the 'Cancel' method on it, the operation seems to cancel, but the server side code is not stopped, and using fiddler I can see that the operation completes and an HTTP status code of 200 is returned.

When you call 'Cancel' what does that do on the server, I would expect it to call a ThreadAbortException or something like that? Can this be improved?

like image 888
peter Avatar asked Nov 03 '22 23:11

peter


1 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.

like image 167
Alastair Pitts Avatar answered Nov 12 '22 14:11

Alastair Pitts