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]);
}
}
Thread-based multitasking deals with the concurrent execution of pieces of the same program. A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.
Can we write multithreading programs in C? Unlike Java, multithreading is not supported by the language standard. POSIX Threads (or Pthreads) is a POSIX standard for threads. Implementation of pthread is available with gcc compiler.
Thread is often referred to as a lightweight process. The process can be split down into so many threads. For example, in a browser, many tabs can be viewed as threads. MS Word uses many threads - formatting text from one thread, processing input from another thread, etc.
A thread is a flow of execution through the process code, with its own program counter that keeps track of which instruction to execute next, system registers which hold its current working variables, and a stack which contains the execution history.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With