私の状況を描いてみましょう:
スレッドを作成する WCF サーバーがあります。そのスレッドはアセンブリを実行し、それを呼び出しましょうABC.exe
。これABC.exe
はこれを行います:
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);
}
どこConnect
で:
objClientThread = new Thread(start) { IsBackground = true };
objClientThread.Start();
と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;
}
}
}
}
これABC.exe
は、WCF を使用してサーバーに接続するクライアントです。
そのため、 s (またはその他のもの)Sleep(Infinite)
を使用する代わりに、はスレッドの終了について通知を受け、実行も終了します。しかし、スレッドを作成するインスタンスの関数を呼び出しているため、通知を受け取る方法がわかりません。manualResetEvent
Main()
Connect
Main
私が望んでいないのは、while(condition) sleep