Guerrilla
Guerrilla

Reputation: 14876

Parameter for new Task

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

Answers (2)

Venkata Dorisala
Venkata Dorisala

Reputation: 5085

    Task t = Task.Factory.StartNew(() => { 
                                          Search("abc"),     
                                          TaskCreationOptions.LongRunning, 
                                          TaskScheduler.Default 
                                          });

Upvotes: 0

Zein Makki
Zein Makki

Reputation: 30022

This should work :

Task t = new Task(() => Search("keyword"));
t.Start();

Upvotes: 2

Related Questions