.NET and ASP.NET interview Question – How will you define threading and show its demonstration?

Threading is a parallel processing unit and helps you to access multiple tasks at a one moment of time. When we want to access parallel processing in our application we use Threading.

In order to use threading we first have to import System.Threading namespace in our application like below code. using System.Threading;

Below is the simple class in which I have defined two functions as Fun1 and Fun2.i have also created a DoTest function with an instance of thread as t1 and t2.finally I have invoked DoTest function in Main Method.

class Program  

{
 public void Fun1()      

{
  for (int i = 0; i < 10; i++)         

{              

Console.WriteLine("i"+"="+i.ToString());              

Thread.Sleep(500);         

}       

}
 public void Fun2()       

{
  for (int j = 0; j < 10; j++)           

{               

Console.WriteLine("j" + "=" +j.ToString());             

Thread.Sleep(500);      

}        

}
  static void Main(string[]args)       

{
   Program p = new Program();        

   p.DoTest();
   Console.ReadLine();       

}
  public void DoTest()       

{
  Thread t1 = new Thread(new ThreadStart(Fun1));     

  Thread t2 = new Thread(new

  ThreadStart(Fun2));
  t1.Start();
  t2.Start();       

}
}

Once you have completed the above steps just run your application and you will see the output like below diagram.
Output:

aa.png

You can see that in the above diagram both the function Fun1 and Fun2 run at single moment of  time with one after another and display their respective outputs.

You will be also interested in watching the below video, which are also asked in most of the interviews and favourable question of interviewers.

Please click here to see more  .NET and ASP.NET interview questions

Regards,

Visit Authors blog for more   .NET and ASP.Net  interview questions
Advertisements

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s