MonsterMMORPG MonsterMMORPG - 10 months ago 43
C# Question

How may I resolve this error? - Delegate 'System.Action<object>' does not take 0 arguments

The following code:

var ui = TaskScheduler.FromCurrentSynchronizationContext();
Task.Factory.StartNew(() => { listBox1.Items.Add("Starting to crawl " + srMainSiteURL + "..."); } , ui);


is resulting in the following error:


Delegate 'System.Action<object>' does not take 0 arguments



After looking at other threads, I have not been able to determine nor understand the cause of the error. Please advise.

Answer Source

Because you did use

public Task StartNew(Action<object> action, object state)

I do think you wanted to use

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download