C# program to demonstrate two threads working concurrently
Program.cs
Explanation:
In this program, we have created the two static methods: thread1() and thread2() in the ParallelThread class. In the main method, we have created the object of Thread class and passed the thread1 and thread2 methods in ThreadStart delegate with classname.methodname. Then, we used Thread.Sleep() method to suspends the current thread for the specified amount of time. At the end, we called Start() method of Thread class with t1 and t2 objects accordingly. The output clearly shows the two thread worked simultaneously.
Output
kodingwindow@kw:~/csharp$ dotnet run 100 200 201 101 202 102 203 204 103 205 104 105 kodingwindow@kw:~/csharp$
What Next?
C# program to set the priorities to the threads
C# program for sleep(), abort() and join() methods
C# program to achieve thread synchronization using the lock keyword
Advertisement