Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# multithreading method name expected

I'm trying to create a loop which creates a thread for each program in a list, but i'm getting a "method name expected" error upon passing perimeters on the code below;

for (i = 0; i <= programs.Count; i++)
{
    checkProcess check = new checkProcess();
    // check.isRunning();

    string filename = programs[i].Filename;
    string filepath = programs[i].Filepath;

    mWorkerThread = new Thread(new ThreadStart(check.isRunning(filename, filepath)));

    mWorkerThread.Start();
}

I read a little on delegates but couldn't seem to get them to work in the context of my problem. Any help would be greatly appreciated as to what direction i should be heading.

like image 846
Kestami Avatar asked Jul 09 '26 15:07

Kestami


1 Answers

The thread target ought to be something executable and not the result of your method.

mWorkerThread = new Thread(new ThreadStart(check.isRunning(filename, filepath)));

In your case above, you try to create a new instance of ThreadStart with the return value of check.IsRunning(...). What you want is something like

mWorkerThread = new Thread( () => check.isRunning(filename, filepath) );
like image 65
Matten Avatar answered Jul 12 '26 14:07

Matten



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!