同步委托线程是没有返回值的,可以有一个Object类型的参数,也可以没有参数
同步委托线程有参数时: Thread thread = new Thread(test)这样创建的同步线程必须有一个object类型的参数
参数是通过start()方法传给委托方法的
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace 同步线程 { class Program { static void Main(string[] args) { Thread thread = new Thread(test);//创建同步线程 thread.Start(10);//将参数传入委托方法中 Console.ReadKey(); } static void test(object a)//委托方法,只能通过start传入一个Object类型的参数 { Console.WriteLine(a); } } }
同步委托线程没有参数时:Thread thread = new Thread(new ThreadStart(test));//创建同步线程,不能向委托方法传参数
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace 同步线程 { class Program { static void Main(string[] args) { Thread thread = new Thread(new ThreadStart(test));//创建同步线程,不能向委托方法传参数 thread.Start(); Console.ReadKey(); } static void test()//委托方法 { Console.WriteLine("a"); } } }