To create a thread, I created a function -
public void myThread() { for (int i = 0; i < 3; i++) { Console.WriteLine("My Thread"); } }
Call the above function to create a thread and create a new ThreadStart delegate-
Demo d = new Demo(); Thread thread = new Thread(new ThreadStart(d.myThread));
Use the following code to create a simple thread.
Real-time demonstration
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; class Demo { public void myThread() { for (int i = 0; i < 3; i++) { Console.WriteLine("My Thread"); } } } class NewThread { public static void Main() { Demo d = new Demo(); Thread thread = new Thread(new ThreadStart(d.myThread)); thread.Start(); Console.Read(); } }
My Thread My Thread My Thread
The above is the detailed content of C# program to create a simple thread. For more information, please follow other related articles on the PHP Chinese website!