How Threading works
- Multi threading is managed by thread scheduler, a function CLR delegates to operating system.
- On a single-processor computer, a thread scheduler performs time-slicing — rapidly switching execution between each of the active threads.
- On a multi-processor computer, multi-threading is implemented with a mixture of time-slicing and genuine concurrency, where different threads run code simultaneously on different CPUs. It’s almost certain there will still be some time-slicing, because of the operating system’s need to service its own threads — as well as those of other applications.
- A thread is said to be preempted when its execution is interrupted due to an external factor such as time-slicing. In most situations, a thread has no control over when and where it’s preempted.
- A thread is the basic unit to which the operating system allocates processor time.
- A process, in the simplest terms, is an executing program which provides resource to running thread.
Different ways to cretate thread and invoke it.
Using Delegate
Public delegate void Threadstart()
Thread t = new Thread(new Threadstart(MethodName())
t.start();
Directly via Method name
Thread t = new Thread( MethodName())
t.start();
Using Lambda Expression
Thread t = new Thread ( () => Console.WriteLine ("Hello!") ); t.Start();