Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedPipeClient"/> class.
 /// </summary>
 /// <param name="pipeName">Name of the pipe.</param>
 /// <param name="connectTimeOut">The connect time out.</param>
 /// <autogeneratedoc />
 public NamedPipeClient(string pipeName, int connectTimeOut)
 {
     try {
         _streams = new NamedPipeClientStreams(pipeName);
         _streams.Connect(connectTimeOut);
     }
     catch {
         _streams?.Dispose();
         throw;
     }
 }
Ejemplo n.º 2
0
        public void ClientServerConnectionTest()
        {
            Helper.RunMta(() => {
                var pipeName         = Guid.NewGuid().ToString("N");
                var server           = new NamedPipeServerStreams(pipeName);
                var client           = new NamedPipeClientStreams(pipeName);
                var serverWaitHandle = new ManualResetEventSlim();
                var clientWaitHandle = new ManualResetEventSlim();

                Task.Run(() => {
                    try {
                        server.WaitForConnection();
                        Console.WriteLine("Server connected");
                        serverWaitHandle.Set();
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex);
                    }
                });
                Task.Run(() => {
                    try {
                        client.Connect();
                        Console.WriteLine("Client connected");
                        clientWaitHandle.Set();
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex);
                    }
                });

                var success = WaitHandle.WaitAll(new[] { serverWaitHandle.WaitHandle, clientWaitHandle.WaitHandle }, 500);

                client.Dispose();
                server.Dispose();

                Assert.AreEqual(true, success);
            });
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NamedPipeClient"/> class.
 /// </summary>
 /// <param name="pipeName">Name of the pipe.</param>
 /// <autogeneratedoc />
 public NamedPipeClient(string pipeName)
 {
     _streams = new NamedPipeClientStreams(pipeName);
 }