In this post, you will learn how to pass a parameter to a Thread.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
class Program { public static void Main() { Thread newThread = new Thread(Program.work1); newThread.Start(10); //passing data Program p = new Program(); newThread = new Thread(p.work2); newThread.Start("Sample Thread"); Console.ReadLine(); } public static void work1(object data) { Console.WriteLine("Static Thread Procedure : Data ='{0}'", data); } public void work2(object data) { Console.WriteLine("Instance Thread Procedure : Data ='{0}'", data); } } |
Output: