相关疑难解决方法(0)

委托.BeginInvoke和在C#中使用ThreadPool线程之间的区别

在C#中,使用委托异步地执行某些工作(调用BeginInvoke())和使用ThreadPool线程之间有任何区别,如下所示

public void asynchronousWork(object num)
    {
        //asynchronous work to be done
        Console.WriteLine(num);
    }

 public void test()
    {
        Action<object> myCustomDelegate = this.asynchronousWork;
        int x = 7;

        //Using Delegate
        myCustomDelegate.BeginInvoke(7, null, null);

        //Using Threadpool
        ThreadPool.QueueUserWorkItem(new WaitCallback(asynchronousWork), 7);
        Thread.Sleep(2000);
    }
Run Code Online (Sandbox Code Playgroud)

编辑:
BeginInvoke确保线程池中的线程用于执行异步代码,所以有什么区别吗?

c# multithreading threadpool

31
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

multithreading ×1

threadpool ×1