views:

862

answers:

2

Hi
I have a WCF function that is executing long time, so I call the function in UI with backgraundworker... I want to give a feature to cancel the execution, so I abort IComunicationObject, the problem is that Service execution is not stoping, Is there any way to stop Service execution in this case?

+1  A: 

Make a CancelOperation() method which sets some static ManualResetEvent in your service. Check this event in your Operation method frequently. Or it can be CancelOperation(Guid operationId) if your service can process multiple operation calls concurrently.

Dmitry Ornatsky
Thanks for response! Is this a good practice? or just a way to do that?
ArsenMkrt
Just a way to do that, not sure if there are any 'best prcactices'
Dmitry Ornatsky
+2  A: 

You may not need a BackgroundWorker. You can either make the operation IsOneWay, or implement the asynchronous pattern. To prevent threading issues, consider using the SynchronizationContext. Programming WCF Services does a great job at explaining these.

Mark Good