Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Threading in C#. Interruptable task

Tags:

c#

concurrency

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]);
    }
}
like image 741
ALOR Avatar asked Aug 11 '09 06:08

ALOR


People also ask

What is threading in C?

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.

Is threading possible in C?

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.

What is thread with example?

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.

What is threading in operating system?

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.


1 Answers

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.

like image 66
JP Alioto Avatar answered Oct 11 '22 19:10

JP Alioto