委托“System.Action<对象>'不带参数0 - C# - 任务 [英] Delegate 'System.Action<object>' does not take 0 arguments - C# - Task
本文介绍了委托“System.Action<对象>'不带参数0 - C# - 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码是给这个错误,我解决不了的原因。
The code below is giving this error and i can not solve the cause.
C#4.0中,任务
var ui = TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(() => { listBox1.Items.Add("Starting to crawl " + srMainSiteURL + "..."); } , ui);
错误消息:委托System.Action不带参数0
the error message : Delegate 'System.Action' does not take 0 arguments
注意:是的,我看了其他线程,但不明白。请不要标记为重复。
推荐答案
由于您没有使用
public Task StartNew(Action<object> action, object state)
我不认为你想用
public Task StartNew(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
所以,你的例子会变成:
So your example would become:
Task.Factory.StartNew(() => { listBox1.Items.Add("Starting to crawl " + srMainSiteURL + "..."); }, CancellationToken.None, TaskCreationOptions.None, ui);
这篇关于委托“System.Action<对象>'不带参数0 - C# - 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文