public bool Connect() { lock (_locker) { SendPipe.Connect(); OPipeHelper.SendClientPid(SendPipe, Process.GetCurrentProcess().Id); var sync = new Synchronizer(true); ReceivePipe.BeginWaitForConnection(ar => { try { ReceivePipe.EndWaitForConnection(ar); sync.Unlock(); } catch (Exception e) { Console.WriteLine(e); } }, null); if (!sync.Wait(7000)) { SendPipe.Close(); ReceivePipe.Close(); throw new Exception("ReceivePipe timeout"); } //ReceivePipe.WaitForConnection(); does not work very well } return(true); }
public bool WaitConnection() { lock (_locker) { ReceivePipe.WaitForConnection(); var clientPid = OPipeHelper.ReadClientPid(ReceivePipe); SendPipe = new NamedPipeClientStream(".", OPipeHelper.GenClientName(_pipeName, clientPid), PipeDirection.Out); SendPipe.Connect(); } return(true); }
public PipeClient(string pipeName) { ReceivePipe = new NamedPipeServerStream(OPipeHelper.GenClientName(pipeName, Process.GetCurrentProcess().Id), PipeDirection.In, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); SendPipe = new NamedPipeClientStream(".", OPipeHelper.GenServerName(pipeName), PipeDirection.Out); }