将匿名方法传递给ProgressBar.Invoke()

Dav*_*New 1 .net c# multithreading invoke winforms

我试图使用匿名方法将委托传递到progressBar.Invoke(Delegate):

progressBar.Invoke(() => progressBar.Value = count);
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

无法将lambda表达式转换为类型'System.Delegate',因为它不是委托类型.

有人可以解释一下我做错了什么吗?

BFr*_*ree 8

该方法采用Delegate,而不是Action.因此,当你这样做时:

() => { .. }
Run Code Online (Sandbox Code Playgroud)

它不知道你想要什么代表.改为:

progressBar.Invoke(new Action(() => progressBar.Value = count));
Run Code Online (Sandbox Code Playgroud)