Asked by:
Cancelling File Syncronization from a background worker.

Question
-
Hello,
I'm currently running a file syncronization via a Background worker and wondered if I could cancel this using a Windows Form button?
My FileSync class contains 3 methods, 1 public and 2 private. The public method calls the 2 private methods DetectChanges and SyncFile. The SyncFile method contains the reference to the SyncOrchestrator class that contains the Syncronize() and Cancel methods().
For some reason I thought I could use the background worker CancelAsync() method but that doesn't seem to be working. Apologies but I'm still learning c#, so any help would be greatly appreciated.
Cheers,
Si.
Thursday, March 1, 2012 8:50 PM
All replies
-
just to clarify, by background worker you mean a separate thread?Thursday, March 1, 2012 11:18 PM
-
Yes, a seperate thread.Thursday, March 1, 2012 11:42 PM
-
have a look at the code posted here. that should resemble how you cancel:
you should call cancel on the orchestrator
Friday, March 2, 2012 12:05 AM -
Thanks June but isnt that code VB? I should have mentioned I'm trying to do this in C#
I knew I call Orchestrator.Cancel() but didnt know how to call it in a thread safe way.
- Edited by siedwards Friday, March 2, 2012 1:06 AM
Friday, March 2, 2012 12:56 AM -
the pattern in the post i referred above should work the same if you do it in C#.
are you trying to cancel the thread where the sync is running hoping that the thread will in turn cancel the sync?
Monday, March 5, 2012 12:48 PM