2. Definition
Threading: A thread is an independent execution path, able to run
simultaneously with other threads.
Multithreading: Multithreading is used to perform multiple tasks at the
same time.
4. Creation
• C# supports 2 methods to create threads
Using the Thread class.
Using the Thread pool.
Thread Class:
A new thread object is created and a delegate is passed to the thread’s constructor.
Thread Pool:
C# provides a pool of threads. Tasks can be assigned to the threads in the pool.
7. Synchronization:
lock (this)
{
for(int i=0;i<5;i++)
Console.WriteLine(“Current thread is {0} and value of i is {1} ”,Thread.CurrentThread.Name,i);
}
9. Wait() Method:
Releases the lock on an object and blocks the current thread until it reacquires
the lock.
Syntax: Monitor.Wait(object);
Pulse() Method:
Notifies a thread in the waiting queue of a change in the locked object's state.
Syntax: Monior.Pulse(object);
10. Deadlock:
A deadlock is a situation where an application locks up because two or more activities are
waiting for each other to finish.
lock(lock1)
{
lock(lock2)
{…}
}