I have two process write and read. I want to complete write process asynchronously using 10 threads and after all thread complete writing. I want to start 5 threads for Reading Process. How to check writing all threads finished its task so that I can signal main thread to start reading process asynchronously by using 5 threads.
public static void MainThread()
{
new Thread(() => WriterThread(10)).Start();
a_ResetEvent.WaitOne();
new Thread(() => ReadWorkerThread(5)).Start();
}
public static void WriterThread(int _noThread)
{
Thread t = null;
for (int i = 0; i < _noThread; i++)
{
t = new Thread(() => Write());
t.Start();
}
if(t.ThreadState != ThreadState.Running)
a_ResetEvent.Set();
}
public static void ReadWorkerThread(int _noThread)
{
for (int i = 0; i < _noThread; i++)
{
new Thread(() => Read()).Start();
}
}
public static void Write()
{
Console.WriteLine($"Writing Thread- {Thread.CurrentThread.ManagedThreadId}");
Thread.Sleep(5000);
Console.WriteLine($"Writing Completed Thread -{Thread.CurrentThread.ManagedThreadId}");
}
public static void Read()
{
Console.WriteLine($"Reading Thread - {Thread.CurrentThread.ManagedThreadId}");
Thread.Sleep(1000);
Console.WriteLine($"Reading Completed Thread - {Thread.CurrentThread.ManagedThreadId}");
}