Threading in c# is pretty straight forward. here are three ways you can do multi threading in c#.
using ThreadStart Method.
namespace Test
{
public class Program
{
private static void M1()
{
Console.WriteLine("Hello, World!");
}
public static void Main(string[] args)
{
Thread t = new Thread(new ThreadStart(M1));
t.Start();
t.Join();
Thread.Sleep(1000);
}
}
}
2. Using anonymous functions
namespace Test
{
public class Program
{
public static void Main(string[] args)
{
Thread t = new Thread(delegate ()
{
Console.WriteLine("Hello, World!");
});
t.Start();
t.Join();
Thread.Sleep(1000);
}
}
}
3. using lambda expression
namespace Test
{
public class Program
{
public static void Main(string[] args)
{
Thread t = new Thread(() =>
{
Console.WriteLine("Hello, World");
});
t.Start();
t.Join();
Thread.Sleep(1000);
}
}
}