public MsgClient(string pipeName) { _pipeName = pipeName; // Process.Start(@"..\..\..\DigitalIOControl\bin\Debug\DigitalIOControl.exe"); //ProcessStartInfo processStartInfo = new ProcessStartInfo(@"DigitalIOControl.exe"); //Process process = new Process(); //process.StartInfo = processStartInfo; //if (process.Start()) //{ _client = TryOpenPipe(); //} }
private NamedPipeClient <MessageContainer> TryOpenPipe() { NamedPipeClient <MessageContainer> client = null; try { client = new NamedPipeClient <MessageContainer>(_pipeName); client.ServerMessage += OnServerMessage; client.Error += OnError; client.Start(); } catch { //TODO } return(client); }
/// <summary> /// Closes all open client connections and stops listening for new ones. /// </summary> public void Stop() { _shouldKeepRunning = false; lock (_connections) { foreach (var client in _connections.ToArray()) { client.Close(); } } // If background thread is still listening for a client to connect, // initiate a dummy connection that will allow the thread to exit. var dummyClient = new NamedPipeClient <TRead, TWrite>(_pipeName); dummyClient.Start(); dummyClient.WaitForConnection(TimeSpan.FromSeconds(2)); dummyClient.Stop(); dummyClient.WaitForDisconnection(TimeSpan.FromSeconds(2)); }