using System;
class abc
{
public static void fun()
{
Console.WriteLine("Function");
}
public static void Main(string[] args)
{
ThreadStart ts=new ThreadStart(fun());
Console.WriteLine("Main begins");
Thread t=new Thread(ts);
t.Start();
Console.WriteLine("Main ends");
}
}
Output showing
Main Begins
Main ends
Function.
My Question
The thread has been started and then the "Main ends" message has been written. When the t.Start() method is invoked the function func() is to be called, but it is completing the work of main function and only returning back to function, why is it so.
If i use static in the function the output is
Main Begins
Function
Main Ends
Why is this change happening. What is the order of execution of threads. Kinly help me.