Thread Execution with join() is different then normal execution. Join() blocks the execution of current thread untill called thread finish the execution. Jion(2) weights for called thread to finish execution in next 2 milliseconds and if not complete it continew the execution process.
Thread Execution With Join() in C# Example:
using System;
using System.Text;
using System.Threading;
namespace Console_App
{
public class Class1
{
public void fun1()
{
for (int i = 0; i < 100; i++)
{
Console.WriteLine(" #" + i );
}
}
}
public class Class2
{
public static void Main()
{
Class1 a = new Class1();
Thread thread1 = new Thread(new ThreadStart(a.fun1));
Console.WriteLine("Before Starting Thread " );
thread1.Start();
thread1.Join(2);
Console.WriteLine("After Staring Thread " );
Console.ReadLine();
}
}
}
No comments:
Post a Comment