.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Threading >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Joining Threads

Posted By:nishithraj       Posted Date: November 27, 2009    Points: 10    Category: Threading    URL: http://www.dotnetspark.com  

If there are two threads running in a same process there may be a chance of exception. (if one thread terminates before another thread). To avoid this kind of issues we have the method Join in threading. If we use this firt will wait for the second thread until it finishes the execution.

public static void Main()
ThreadStart worker = new ThreadStart(Callme);
Thread t = new Thread(worker);
t.Name="My 1st Thread";
//Starting a thread
System.Configuration.AppSettingsReader myReader =
new System.Configuration.AppSettingsReader();
int timeout=int.Parse(myReader.GetValue
Console.WriteLine("Timeout "+timeout);
//Joining the two threads
if (t.IsAlive)
Console.WriteLine("X= " + x +" Main - Bye");


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend