我该如何解决这个错误?- 委托'System.Action<object>'不接受 0 个参数 [英] How may I resolve this error? - Delegate 'System.Action<object>' does not take 0 arguments
本文介绍了我该如何解决这个错误?- 委托'System.Action<object>'不接受 0 个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码:
var ui = TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(() => { listBox1.Items.Add("Starting to crawl " + srMainSiteURL + "..."); } , ui);
导致以下错误:
委托 'System.Action
查看其他线程后,我一直无法确定或理解错误的原因.请指教.
After looking at other threads, I have not been able to determine nor understand the cause of the error. Please advise.
推荐答案
因为你确实用过
public Task StartNew(Action<object> action, object state)
我确实认为您想使用
public Task StartNew(Action action, CancellationToken cancellationToken, TaskCreationOptions creationOptions, TaskScheduler scheduler)
所以你的例子会变成:
Task.Factory.StartNew(() => { listBox1.Items.Add("Starting to crawl " + srMainSiteURL + "..."); }, CancellationToken.None, TaskCreationOptions.None, ui);
这篇关于我该如何解决这个错误?- 委托'System.Action<object>'不接受 0 个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文