Now, I have function working well like this.
StartWorking() {
mThread = new Thread(fooFunction);
mMonitorThread = new Thread(MonitoringThreadFunction);
mThread.Start();
mMonitorintThread.Start();
}
Now, I need add a loog for this code. Letting it run several times in a row. Sequentially.
I tried do this. But it is messed up. Thread’s work is not working right.
StartWorking()
{
for(int i = 0; i < 3; i++)
{
mThread = new Thread(fooFunction);
mMonitorThread = new Thread(MonitoringThreadFunction);
mThread.Start();
mMonitorintThread.Start();
}
}
So, what should I do for my purporse?
Try
or, if you’re on .NET ≥ 4, use
System.Threading.CountdownEventwith InitialCount = 2 and pass it in theThread.Start()method.Edit: yet, the TPL solution is definitely cleaner.