Reputation: 14876
I have a console app that launched a task like this in the main method:
Task t = new Task(Search);
t.Start();
I want to change the Search()
method to accept a parameter but when I do then I try the below code I get an error about converting void to an action:
Task t = new Task(Search("keyword"));
t.Start();
What is the proper way to be passing a parameter?
Upvotes: 0
Views: 50
Reputation: 5085
Task t = Task.Factory.StartNew(() => {
Search("abc"),
TaskCreationOptions.LongRunning,
TaskScheduler.Default
});
Upvotes: 0
Reputation: 30022
This should work :
Task t = new Task(() => Search("keyword"));
t.Start();
Upvotes: 2