Permettez-moi de peindre ma situation:Attendre le thread qui crée une instance qui crée un thread
J'ai un serveur WCF qui crée un thread. Ce thread exécute un assembly, appelons-le ABC.exe
. Ce ABC.exe
ce que cela:
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);
}
Où Connect
fait:
objClientThread = new Thread(start) { IsBackground = true };
objClientThread.Start();
Et 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;
}
}
}
}
ce ABC.exe
est le client qui se connecte au serveur avec WCF.
Ainsi, au lieu d'avoir la Sleep(Infinite)
que je veux utiliser manualResetEvent
s (ou autre chose) de sorte que le Main()
est notifié sur l'extrémité du fil qui Connect
marques et mettre fin à son exécution aussi. Mais je ne sais pas comment le Main
peut être averti, car il appelle une fonction d'une instance qui crée un thread.
Ce que je ne veux pas est une attente active où il y a un while(condition) sleep
Pourquoi enfilez-vous du tout dans ce projet ABC? Le thread principal attend seulement l'autre. –
Vous avez plusieurs 'Sleep()' s. Considérez chacun un défaut de conception. –
Il est déjà conçu comme ça, je dois juste changer le sleep.infinite et le faire attendre jusqu'à ce que le thread créé avec la connexion se termine. – AAlferez