private void Start() { try { while (_listen) { int[] keys = new int[Pipes.Keys.Count]; Pipes.Keys.CopyTo(keys, 0); foreach (int key in keys) { ServerNamedPipe serverPipe = (ServerNamedPipe)Pipes[key]; if (serverPipe != null && DateTime.Now.Subtract(serverPipe.LastAction).Milliseconds > PIPE_MAX_STUFFED_TIME && serverPipe.PipeConnection.GetState() != InterProcessConnectionState.WaitingForClient) { serverPipe.Listen = false; serverPipe.PipeThread.Abort(); RemoveServerChannel(serverPipe.PipeConnection.NativeHandle); } } if (numChannels <= NumberPipes) { ServerNamedPipe pipe = new ServerNamedPipe(PipeName, OutBuffer, InBuffer, MAX_READ_BYTES, false, this); try { pipe.Connect(); pipe.LastAction = DateTime.Now; System.Threading.Interlocked.Increment(ref numChannels); pipe.Start(); Pipes.Add(pipe.PipeConnection.NativeHandle, pipe); } catch (InterProcessIOException) { RemoveServerChannel(pipe.PipeConnection.NativeHandle); pipe.Dispose(); } } else { Mre.Reset(); Mre.WaitOne(1000, false); } } } catch { // Log exception } }
private void Start() { try { while (_listen) { int[] keys = new int[Pipes.Keys.Count]; Pipes.Keys.CopyTo(keys,0); foreach (int key in keys) { ServerNamedPipe serverPipe = (ServerNamedPipe)Pipes[key]; if (serverPipe != null && DateTime.Now.Subtract(serverPipe.LastAction).Milliseconds > PIPE_MAX_STUFFED_TIME && serverPipe.PipeConnection.GetState() != InterProcessConnectionState.WaitingForClient) { serverPipe.Listen = false; serverPipe.PipeThread.Abort(); RemoveServerChannel(serverPipe.PipeConnection.NativeHandle); } } if (numChannels <= NumberPipes) { ServerNamedPipe pipe = new ServerNamedPipe(PipeName, OutBuffer, InBuffer, MAX_READ_BYTES, false, this); try { pipe.Connect(); pipe.LastAction = DateTime.Now; System.Threading.Interlocked.Increment(ref numChannels); pipe.Start(); Pipes.Add(pipe.PipeConnection.NativeHandle, pipe); } catch (InterProcessIOException) { RemoveServerChannel(pipe.PipeConnection.NativeHandle); pipe.Dispose(); } } else { Mre.Reset(); Mre.WaitOne(1000, false); } } } catch { // Log exception } }