5

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?

peter
  • 13,009
  • 22
  • 82
  • 142

2 Answers2

2

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.

Alastair Pitts
  • 19,423
  • 9
  • 68
  • 97
  • Yeah, that is what I was thinking, but it doesn't really answer the question. This cancel thing is only useful to me if it stops the request on the server too as it includes SQL statements which will load up the SQL server. If there is no way to do this then I won't use cancel. – peter Jun 04 '12 at 22:02
  • yeah, unfortunately there isn't a way to cancel that server-side operation. – Alastair Pitts Jun 04 '12 at 22:50
0

From what I understand cancel of serverside execution using the loadoperation is not available.

you could tough run your own cancel impelmentation: (depending on if you are using DomainService base or LinqToEntitiesDomainService base the impelmentation will variate)

sevice side

in your service method start the load in a new thread put that thread object in the session your thread object should be in a way that you can cancel the DbConnection... perpare a service method (Invoke) to Cancel the currently executing thread object registered in the session, and remove it from the session

client side

call cancel on the LoadOperation object and invoke the cancel request.

one caveat is that you comment out the OnSessionStart and stop in global.asax in order to execute ria services in a multithreaded way per user else each request will wait till a previous request is finished (this has to do with ria service threads and not our thread object)

hope this helps best regards

PS: we also use a similar solution for pessimistic lock with RIA Services and EntityFramework, ...

Stefan U7
  • 61
  • 4