更新时间:2023-02-07 20:46:48
You can use a Task
to achieve this:
public class ThreadTest {
public static void Main(string[] args)
{
Task task = new Task(() => ... // Code to run here);
task.Start();
}
}
正如@JonSkeet所指出的那样,如果不需要分开创建和计划,则可以使用:
As @JonSkeet points out, if you do not need to separate creation and scheduling you could use:
Task task = Task.Factory.StartNew(() => ... // Code to run here);
或者在.Net 4.5+中:
Or in .Net 4.5+:
Task task = Task.Run(() => ... // Code to run here);