Question

I'm looking a method to wait all threads while a thread in a void...

I have normally 10 threads running.

And I have a void, which is important...

All threads entering that void together. I would like to wait other threads out of void or start of void...

For example:

    public static void theVoid(int ID)
    {
        //<THREADS WAIT STATION>
        //ACTIONS
        //ACTIONS
        //<ONE THREAD STILL PROCESSING>
        Console.WriteLine("Test");
    }

If one thread finish the operation of void or reach end of line of the void other thread will continue.

And same...

How can I do it?

Thanks a lot.

Was it helpful?

Solution

Would a lock work for you?

private static object gate = new object();

public static void theVoid(int ID)
{
    lock (gate)
    {
        //<THREADS WAIT STATION>
        //ACTIONS
        //ACTIONS
        //<ONE THREAD STILL PROCESSING>
        Console.WriteLine("Test");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top