一、异步委托开启线程

public static void Main(string[] args){

Action<int,int> a=add;
a.BeginInvoke(3,4,null,null);//前两个是add方法的参数,后两个可以为空
Console.WriteLine("main()");
Console.ReadKey();


static void add(int a,int b)
Console.WriteLine(a+b);


static void add(int a,int b){
Console.WriteLine(a+b);

二 、使用threadPool

ThreadPool.QueueUserWorkItem("方法名");
ThreadPool.QueueUserWorkItem("方法名");
ThreadPool.QueueUserWorkItem("方法名");
ThreadPool.QueueUserWorkItem("方法名"); //带有参数object

三 、 使用Task new的方式

Task task = new Task(()=> Console.WriteLine("开启任务异步多线程3") );

四、使用Task Factory的方式

  Task task1 = Task.Factory.StartNew(() =>  Console.WriteLine("开启任务异步多线程4"));

 

转自:https://www.cnblogs.com/dashanboke/p/10650502.html

相关文章:

  • 2021-09-30
  • 2021-08-12
  • 2022-12-23
  • 2021-11-07
  • 2021-04-12
  • 2022-12-23
  • 2021-11-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2021-11-11
相关资源
相似解决方案