BackgroundWorker with anonymous methods?

前端 未结 4 1450
猫巷女王i
猫巷女王i 2021-02-05 03:55

I\'m gonna create a BackgroundWorker with an anonymous method.
I\'ve written the following code :

BackgroundWorker bgw = new B         


        
4条回答
  •  眼角桃花
    2021-02-05 04:19

    If you specify a lambda, you must ensure it takes the same number of arguments:

    bgw.DoWork += (s, e) => ...;
    

    But if you're not using the arguments, you could just use an anonymous delegate without parameters:

    bgw.DoWork += delegate
    {
        ...
    };
    

提交回复
热议问题