tags:

views:

92

answers:

3

In my program i have some very long task, which should be interruptable from GUI (WPF). Any advices about threading architecture?

This task looks like N thread with such code:

public void DoLongOperation()
{
    for(int i=beginPoint; i<endPoint; i++)
    {
       doSomethingStupid(dataArray[i]);
    }
}
+9  A: 

Take a look at BackgroundWorker; specifically, WorkerSupportsCancellation. There is an example of what you want to do at WPF Multithreading: Using the BackgroundWorker and Reporting the Progress to the UI.

JP Alioto
This is a great choice. +1
280Z28
Yeah, really useful and simple. I knew about this class, but never used it. Thx
ALOR
A: 

Well, you can either check to see if it should be stopped, each loop iteration, by checking a bool. Or just .interrupt() it, and handle the exception (if it's safe for it to be killed at any time).

Noon Silk
A: 

.Interrupt() on a thread is not the good way, the only good way is with a bool as you say in your answer.

Coolweb