스레드를 만드는 클라이언트가 있습니다.ManualResetEvent가 작동하지 않습니다. 스레드
그 스레드는 WaitOne()
이므로 거기에 붙어있는 동안 내 클라이언트는 죽지 않습니다. 그러나 클라이언트를 종료하려면 해당 수동 재설정 이벤트에서 Set()
을 수행해야합니다.
public ManualResetEvent mreIn = new ManualResetEvent(false);
이 시작 기능 스레드 만들어 내 Connect
기능입니다 :
public void Connect()
{
objClientThread = new Thread(start) { IsBackground = true };
objClientThread.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
mreIn.WaitOne();
if (OnShutdownInitiated != null)
{
OnShutdownInitiated(this, new EventArgs());
}
System.Threading.Thread.Sleep(500);
objProxy.Close();
objConfiguration = null;
IsConnected = false;
mreOut.Set();
}
}
을 그리고 난 않는 콜백이 Set()
:
Boolean IServiceCallbackContract.Shutdown()
{
mreIn.Set();
return true;
}
그래서 방법 일 is works is ... 모든 모듈이 초기화되고 차단되었습니다. WaitOne()
모듈을 종료하면 콜백은 Set()
을 수행하지만 WaitOne()
은 잠금 해제되지 않고 스레드가 계속되지 않습니다. 내가 무엇이 누락 되었습니까?
첫 번째 확인 : 동일한 인스턴스에서 콜백이 실행됩니까? –
예, 콜백은 동일한 인스턴스를 실행합니다. 클라이언트는 executeAssembly와 함께 실행되는'.exe '입니다. 이'.exe'는 클라이언트 클래스의 인스턴스를 가지고 있습니다. 'exe'가 시작되면'Connect()'함수가 호출되어 스레드를 생성합니다 – AAlferez
그러나 objProxy는 잘못 명명 된 호스트처럼 보입니다. –