Sample of MulthiThreaded Application using C#.Net: Part III
Writing multithreaded application in C# in pretty easy. The following article shows the steps to be followed while writing a multithreaded program.
Writing multithreaded application in C# in pretty easy. The following are the steps to be followed while writing a multithreaded program.
Step 1: Define Namespace
Since in .NET, threading functionality is defined in System.Threading namespace we have to define it before using any thread class.
Step 2: Start a thread
The Thread class of System.Threading namespace represents a Thread object. By using this class object, you can create new threads, delete, pause, and rÃ©sumÃ© threads. The Thread class creates a new thread and thread. Start method starts the thread. The general syntax for initializing a new instance of the thread class is given blow.
static void Main(string args)
Console.WriteLine("Main Thread" + j.ToString());
//When Start will called, the new thread will begin executing the ThreadStart delegate //passed
in the constructor. Once the thread is dead, it cannot be restarted with //another call to start.
Thread thread = new Thread(new ThreadStart(WriteData));
/// WriteData is a function which will be executed by the thread
protected static void WriteData()
for (int i = 0; i <= 10; i++)
str = "Secondary Thread" + i.ToString();
And the output will be:
For more Threading Concepts, refer :
Basic concepts of Threading: Part I
Basic concepts of Threading: Part II
Important Properties and Methods of Threads: Part IV