kadabba

In this Use Case user initiate a long process (it may takes hours to complete) by sending some criteria to the server. The user must be able to cancel the process.

But it seems whenever user cancel the client thread the server thread keeps running til its completion.

Is there any way to notify the server of the thread cancellation

More info:

.Net Remoting 2.0
SingleCall, Server Activated Model



Re: .NET Remoting and Runtime Serialization How to Cancel Execution Thread on the Server Side?

Sowmy Srinivasan

There is no built in support for async cancellation. However you could have an app level cancellation logic.






Re: .NET Remoting and Runtime Serialization How to Cancel Execution Thread on the Server Side?

kadabba

Thanks for reply.

Can you elaborate more My problem is, I can send cancel event to the server, but I don't know how to stop the execution thread. Please note that this is a stateless scenario.

Thanks again.





Re: .NET Remoting and Runtime Serialization How to Cancel Execution Thread on the Server Side?

Surya Suluh

I suggest you use BackgroundWorker class to run your work. When cancel is sent by the client, your server will handle this by working the cancelling via the BackgroundWorker instance for that work. I've used this implementation within my project and it has been reliable so far.



Re: .NET Remoting and Runtime Serialization How to Cancel Execution Thread on the Server Side?

kadabba

Thanks for the reply. But I don't think this solution works properly in this scenario. You should note that the connection is stateless, much like an ASP.Net application, that means after the client issue a request, it will forget all about the server.

However, with the help of one of my friends, I was able to implement a relatively good solution for this. I keep a dictionary in the Application object, which is consisting of a GUID and a cancellation class. For each client request the server assign a guid to the client, and add the guid with a cancellation class in the clean state to the dictionary. When client wants to cancel the request, it sends the guid, which was generated by server, along with the cancellation class to the server, this will trigger a cancellation event on the server side which cause the process gets canceled.

Thanks again.