.Net Interview Questions and Answers

Search:

.NET interview questions: - What are the different types of threadstate in C# threading?

By : Shiv Prasad Koirala | May 26th, 2012 | Views : 3442 | Comments : 0 Bookmark and Share

Sometimes people ask funny questions and they think that developers are walking c# encyclopedia. They expect .NET developers to know each and every method name, property name….sick, but then that's the reality.

 

One of our candidates who had bought from us Dotnet interview questions and answers  videos was recently stumped with one such question, what are the different types of states in c# threading.

 

In some of the .NET interviews I have seen people making it sophisticated by saying "Explain c# threading lifecycle?".

 

In case you are completely fresher in threading you can start from C# threading videos from here.

 

Such kind of questions needs stupid ways of remembering. There are 5 states of threading Running, Wait/Sleep/Join,Abort , Resume and Suspend. "Running" state is easy to remember, the others you can remember by the word "WARS". Below is an explanatory figure for the same.

 

threading

At the end I have also put a state flow chart diagram which explains how threads move from one state to other state.

 

Stop to Running: -When a new thread is created it start with a stop or in anunstarted state. If you start the thread by invoking the "Thread.Start" the thread is moves in to a running state.

threading

 

Running to Abort: - When a thread is in a running state it can move to 3 different states. If the thread terminates it will move to aborted state finally leading to stop state. You can also abort a thread by calling "Abort" function of the thread object this will move the thread to abort state.

 

threading

 

Running to Suspended: - As said previously your thread can move from running state to three different states one of them is suspended. If you call the "Suspend" method the thread is suspended and will be revoked back to the running state if you call "Resume" method.

 

threading4

 

threading5

 

Running to Wait/Sleep/Join: - A thread can go to "WaitSleepJoin"in 3 ways, the first one is when the "Monitors" "Wait" method is called.

 

threading6

 

Thread will again go back to "Running" state when the "Pulse" method of the "Monitor" object is called.

 

threading7

 

The second way by which "Thread" can go in "WaitSleepJoin" is by calling the "Sleep" method of the thread object.

 

threading8

 

After the specified millisecond elapses the thread comes back to "Running" state.

 

The third way is call the join method. When the join method is called the thread goes in the "WaitSleepJoin" state. Once the other thread finishes this dependent thread is released either to "Running" or "Aborted" depending on what kind of logic it's currently running.

 

threading9

 

Below is a complete life cycle of C# threads.

 

threading10

 

You can see the following video on C# threading of thread safety: -

 

 

In case you are completely fresh in C#, you can start from our C# training videos step by step.

 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

WCF Interview questions and answers: -What is the difference between WCF fault exceptions and normal .NET exceptions?

In this article we will show difference between WCF fault exceptions and normal .NET exceptions. For more articles and videos visit us on http://www.questpond.com/... Read More

.NET interview questions: - Can you elaborate project life cycle?

In this article we will explain about project life cycle. For more articles and videos visit us on http://www.questpond.com/... Read More

WCF Interview questions:- Which binding do we need to use for WCF REST?

In this article we will show Binding used for WCF REST. For more articles and videos visit us on www.questpond.com... Read More

SQL server interview question: -What are Sub-Queries, co-related queries and difference between them?

In this article we will explain about Sub-Queries and co-related queries. For more articles and videos visit us on http://www.questpond.com/... Read More

Five most important SharePoint 2010 interview questions

This article will give answers to 5 most asked questions in the interview.... Read More

WCF Interview questions and answers: -What is the difference between WCF fault exceptions and normal .NET exceptions?

In this article we will show difference between WCF fault exceptions and normal .NET exceptions. For more articles and videos visit us on http://www.questpond.com/... Read More

.NET interview questions: - Can you elaborate project life cycle?

In this article we will explain about project life cycle. For more articles and videos visit us on http://www.questpond.com/... Read More

WCF Interview questions:- Which binding do we need to use for WCF REST?

In this article we will show Binding used for WCF REST. For more articles and videos visit us on www.questpond.com... Read More

SQL server interview question: -What are Sub-Queries, co-related queries and difference between them?

In this article we will explain about Sub-Queries and co-related queries. For more articles and videos visit us on http://www.questpond.com/... Read More

Five most important SharePoint 2010 interview questions

This article will give answers to 5 most asked questions in the interview.... Read More

Article Categories