how to stop the long running asyncrhronous operation task RRS feed

  • Question

  • hi All,

     i have created one sample wcf service application with some asynchronous callback methods and i'm consuming the WCF service using windows application client which have two buttons start and cancel .

    when i click the start button the service methods will be call  and if  i click the cancel button before completing the operation needs to be stop in WCF service.

    please help me how to make this  task work and earlier response will be highly appreciated.

    note: im using .net framewok 4.0

    uploaded the sample solution which i tried in the following link.



    Sudhesh. G <br/> <a href="" target="_blank"></a><br/>

    Wednesday, August 28, 2013 12:46 PM


  • For a method to support cancellation the .NET Framework 4.0 introduced a new cancellation model based on an object called CancellationToken:

    However, it is important to be aware of the fact that this model doesn’t come with any guarantees. Cancellation cannot really occur without the explicit support of the operation to be cancelled. This means that the operation to be canceled needs to take a CancellationToken as an argument and decide when to honour a request for cancellation from the user, typically by polling the token to find out if a cancellation request was made.

    Once the client has sent the request to the service and all the bytes have been transmitted on to the network there is no way of cancelling the operation. If the operation performs some long-running work on the server side, you could define a bool field in your service, check this regularly and stop if it is set to true. You could then expose another method in your service that simply sets this variable to true and have your client call this method to request a cancellation. Note that the implementation of this depends on which InstanceContextMode you are using.

    Wednesday, August 28, 2013 2:47 PM