Top 10 C# / .NET Multithreading Interview Questions

Question 1. What is the difference between Threads and Tasks? Tasks are wrapper around Thread and ThreadPool classes. Below are some major differences between Threads and Tasks: A Task can return a result but there is no proper way to return a result from Thread. We can apply chaining on multiple tasks but we can not in threads. We can wait on Tasks without us...

Continue Reading

C# Barrier

C# Barrier class is synchronization primitives used in .NET threading. Barrier is used in an algorithm which composed of multiple phases.  In this Barrier synchronization, we have multiple threads working on a single algorithm. Algorithm works in phases. All threads must complete phase 1 then they can continue to phase 2. Until all the threads do not complete the p...

Continue Reading

C# CountdownEvent

C# CountdownEvent is a synchronization primitive which unblocks a waiting thread when its receives signal a certain number of times. CountdownEvent is used in fork-join scenarios. As shown in the above diagram, master thread divides its work into 3 parallel tasks. After all parallel tasks are completed, then it joins its results and control goes back to the mas...

Continue Reading

C# Semaphore

C# semaphore allows only a limited number of threads to enter into a critical section. Semaphore is mainly used in scenarios where we have limited number of resources and we have to limit the number of threads that can use it. How Semaphore Works Semaphores are Int32 variables stored in a operating system resources. When we initialize the semaphore object we initiali...

Continue Reading

ManualResetEvent

ManualResetEvent like AutoResetEvent is another synchronization techniques in .NET threading.  ManualResetEvent is used for send signals between two or more threads. Multiple threads can enter into a waiting/blocking state by calling the WaitOne method on ManualResetEvent object. When controlling thread calls the Set method all the waiting threads are u...

Continue Reading

AutoResetEvent

AutoResetEvent is one of the easy synchronization primitives in .NET threading synchronization. AutoResetEvent is used for send signals between two threads. Both threads share the same AutoResetEvent object. Thread can enter into a wait state by calling WaitOne() method of AutoResetEvent object. When second thread calls the Set() method it unblocks the waiting thread....

Continue Reading

Synchronization Tutorials

One of the benefits of using multithreading in .NET is to improve the performance of our applications. We execute long running tasks in the background threads and make the UI thread idle to get the user's inputs. We share resources between multiple threads such as memory. If multiple threads will try to update the data at the same time, the memory get corrupted and ...

Continue Reading

Join our newsletter and get an occasional email with a technology and dotnetpattern.com news update.