C#之线程ThreadStart
2020-12-13 05:37
标签:方法 tar read 需要 创建线程 返回值 nbsp 运行 lin 本来自于https://docs.microsoft.com/zh-cn/dotnet/api/system.threading.threadstart?view=netframework-4.8; C#之线程ThreadStart 标签:方法 tar read 需要 创建线程 返回值 nbsp 运行 lin 原文地址:https://www.cnblogs.com/xingyuanzier/p/11144322.html
{
ThreadStart threadStartDelegate = new ThreadStart(Work.DoWork); //创建委托
Thread thread = new Thread(threadStartDelegate); //用ThreadStart委托实例化线程Thread
thread.Start();
work.Data = 42;
threadStartDelegate = new ThreadStart(work.DoMoreWork);
thread = new Thread(threadStartDelegate);
thread.Start();
Console.ReadKey();
}
{
public static void DoWork()
{
Console.WriteLine("Static thread procedure.");
}
public int Data;
public void DoMoreWork()
{
Console.WriteLine("Instance thread procedure. Data={0}", Data);
}
}