65.9K
CodeProject is changing. Read more.
Home

How to run method in separate thread

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.50/5 (3 votes)

Mar 24, 2011

CPOL
viewsIcon

38993

Multithreading

Here is the main method which can run a method in a separate thread:

private static void RunMethodInSeparateThread(Action action)
{
    var thread = new Thread(new ThreadStart(action));
    thread.Start();
}

Here is how to use this method:

private static void Method1()
{
    //Method1 implementation
}

private static void Method2()
{
    //Method2 implementation
}

static void Main(string[] args)
{
    RunMethodInSeparateThread(Method1);
    RunMethodInSeparateThread(Method2);
}
How to run method in separate thread - CodeProject