C# Threading Example: static methodWe can call static and non-static methods on the execution of the thread. To call the static and non-static methods, you need to pass method name in the constructor of ThreadStart class. For static method, we don't need to create the instance of the class. You can refer it by the name of class. Output: The output of the above program can be anything because there is context switching between the threads. 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 6 7 8 9 C# Threading Example: non-static methodFor non-static method, you need to create instance of the class so that you can refer it in the constructor of ThreadStart class. Output: Like above program output, the output of this program can be anything because there is context switching between the threads. 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 6 7 8 9 C# Threading Example: performing different tasks on each threadLet's see an example where we are executing different methods on each thread. Output: task one task two Next TopicC# Thread Sleep |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India