public static RepeatThread Start(string name, Action task, Action<RepeatThread, Action> run) { RepeatThread result = new RepeatThread(); Action wrappedTask = Error.Log.Wrap(string.Format("Thread \"{0}\" Failed.", name), () => { try { task.Call(); } catch (System.Threading.ThreadInterruptedException) { result.End = true; } catch (System.Threading.ThreadAbortException) { result.End = true; } }); run(result, () => { result.Running = true; while (!result.End) wrappedTask(); result.Running = false; }); return result; }
public virtual void Dispose() { if (this.listener.NotNull()) this.Stop(); if (this.listener.NotNull()) { this.listener.Abort(); this.listener.Dispose(); this.listener = null; this.tcpListener = null; } if (this.activeConnections.NotNull()) { this.activeConnections.Apply(c => c.Close()); this.activeConnections = null; } }
public bool Start(Uri.Endpoint endPoint) { return this.Start(endPoint, action => this.listener = Parallel.RepeatThread.Start("TcpServer", action)); }
public bool Run(Uri.Endpoint endPoint) { return this.Start(endPoint, action => this.listener = Parallel.RepeatThread.Run(action)); }