Threading in C#

 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

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...