Wait on thread that creates an intance that creates a thread
Let me paint my situation:
I have a WCF server which creates a thread. That thread executes an
assembly, lets call it ABC.exe. This ABC.exe does this:
static void Main(string[] args)
{
objClientBase.OnHandshakeCompleted += new
EventHandler(objClientBase_OnHandshakeCompleted);
objClientBase.OnShutdownInitiated += new
EventHandler(objClientBase_OnShutdownInitiated);
objClientBase.Connect();
objOEEMon = new Main();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
Where Connect does:
objClientThread = new Thread(start) { IsBackground = true };
objClientThread.Start();
And start
/// <summary>
/// Starts the client program.
/// </summary>
private void start()
{
//We Open the proxy to let connections happen
objProxy.Open();
if (performHandshake())
{
IsConnected = true;
DelayedShutdownBool = false;
//While connected, the thread keeps the client alive
while (IsConnected)
{
System.Threading.Thread.Sleep(500);
if (DelayedShutdownBool)
{
System.Threading.Thread.Sleep(500);
objProxy.Close();
objConfiguration = null;
IsConnected = false;
}
}
}
}
this ABC.exe is the client which connects to the server with WCF.
So instead of having the Sleep(Infinite) I want to use manualResetEvents
(or other thing) so the Main() gets notified about the end of the thread
that Connect makes and end his execution too. But I dont know how the Main
can get notified, because is calling a function of an instance that
creates a thread.
What I dont want is a active wait where thre is a while(condition) sleep
Any suggestions are appreciated
No comments:
Post a Comment