This project is read-only.

ParallelFox - stop an already running task

Topics: General
Jan 24, 2012 at 9:05 PM

I'm running some functions in different workers with ParallelFox. Is there a way to stop the execution of one or more of the parallel executed functions before it's completed?

Jan 25, 2012 at 1:15 AM

There's no built-in functionality to stop code running or to kill a worker.  You can call Parallel.StopWorkers(.T.) to stop all workers immediately, but I don't think that's what you are looking for.   In your worker code, you can periodically check the main process to see if the code should continue.  For example, you could create an object with an lCancel parameter.  Pass this object as a parameter to your worker.  When you want to cancel the program, set MyObject.lCancel to .T. in the main process.   In the worker, periodically check if MyObject.lCancel = .T., and if it is, exit the program.  Note that every time you check MyObject.lCancel, you are traversing COM to get the value, so if you call it a lot, you'll take a performance hit. 

If you have additional work in the queue, you may also want to call Parallel.ClearQueue() in the main process to cancel that work.

I'm going to think about how to build this type of functionality into ParallelFox for a future release.  Let me know if you have any questions.