I currently have this code (thanks for the help from here). I need to create the first ProcessMessage as a thread and run the second ProcessMessage synchronously (on the current thread), then perform the Join on the single thread. Otherwise, I’ll have three threads doing effectively two things. How do I modify this to accomplish it? I am on .NET 3.5
Thread thRegion1 = new Thread(() =>
{
if (Region1.Trim().Length > 0)
{
returnMessage = ProcessTheMessage(string.Format(queueName, Region1));
Logger.Log(returnMessage);
}
});
Thread thRegion2 = new Thread(() =>
{
if (Region2.Trim().Length > 0)
{
returnMessage = ProcessTheMessage(string.Format(queueName, Region2));
Logger.Log(returnMessage);
}
});
thRegion1.Start();
thRegion2.Start();
thRegion1.Join();
thRegion2.Join();
You can do it like this:
This starts the
thRegion1thread and performs the other part of the work in the current thread. After that work is finished, it callsJoinonthRegion1which will return immediately, ifthRegion1is already finished with its work.