コード例 #1
0
ファイル: OPipeClient.cs プロジェクト: YogurtTheHorse/Ogam3
        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);
        }
コード例 #2
0
ファイル: OPipeServer.cs プロジェクト: YogurtTheHorse/Ogam3
        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);
        }
コード例 #3
0
ファイル: OPipeClient.cs プロジェクト: YogurtTheHorse/Ogam3
 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);
 }