Threading in C#
Threading allows a program to perform multiple tasks concurrently. C# provides several classes and interfaces in the System.Threading namespace to support threading. Here's an example code that demonstrates how to create a new thread and start it:
class MyThread
{
public void ThreadProc()
{
Console.WriteLine("Thread started.");
Thread.Sleep(5000);
Console.WriteLine("Thread ended.");
}
}
MyThread obj = new MyThread();
Thread t = new Thread(obj.ThreadProc);
t.Start();
No comments:
Post a Comment