• C#开启异步 线程的四种方式(二)


    一、异步委托开启线程

    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

    在通往幸福道路上,并没有什么捷径可走,唯有付出努力和拼搏
  • 相关阅读:
    单例模式(Singleton)
    cdlinux
    android 去锯齿
    ide
    图片加载内存溢出
    android AlertDialog 弹出窗
    找回 文件下载 ie 窗口
    javac 多个jar文件 用封号 隔开
    android 模拟按钮点击
    android 加载多个图片 内在溢出的问题
  • 原文地址:https://www.cnblogs.com/xinhuawei/p/15570777.html
Copyright © 2020-2023  润新知