Not sure my headline is well worded, but whatever :)
I have two threads: the main thread with the work to be done, and the workflow containing the form with a progress bar and a cancel button. In normal code, this would be the other way around, but I cannot do this in this case.
When the user clicks the cancel button, a prompt is displayed asking if he really wants to cancel the job. The problem is that the work continues in the main thread. I can make the main thread stop working and so on, but I would like it to stop working when it clicks “Yes” at the prompt.
Example:
t1 = new Thread(new ThreadStart(progressForm_Start));
t1.Start();
for (i = 0; i <= 10000; i++)
{
semaphore.WaitOne();
if (pBar.Running)
bgworker_ProgressChanged(i);
semaphore.Release();
if (pBar.IsCancelled) break;
}
t1.Abort();
void progressForm_Start()
{
pBar.Status("Starting");
pBar.ShowDialog();
}
cancelWatch(), , .