/// <summary> /// Executes the test method, failing if it takes too long. /// </summary> /// <returns>Returns information about the test run</returns> public override MethodResult Execute(object testClass) { WorkerThreadHandler timedMethod = () => { return(InnerCommand.Execute(testClass)); }; IAsyncResult asyncResult = timedMethod.BeginInvoke(null, null); MethodResult methodResult; if (!asyncResult.AsyncWaitHandle.WaitOne(Timeout, false)) { methodResult = new FailedResult(testMethod, new TimeoutException(Timeout), DisplayName); } else { methodResult = timedMethod.EndInvoke(asyncResult); } return(methodResult); }
public MainThreadHandler() { myTcpListener = new TcpListener(10000); myTcpListener.Start(); Console.WriteLine("Listener started. Press Ctrl+Break to stop."); while (true) { while (!myTcpListener.Pending()) { Thread.Sleep(1000); } WorkerThreadHandler myWorkerThreadHandler = new WorkerThreadHandler(); myWorkerThreadHandler.myTcpListener = this.myTcpListener; ThreadStart myThreadStart = new ThreadStart(myWorkerThreadHandler.HandleThread); Thread myWorkerThread = new Thread(myThreadStart); myWorkerThread.Name = "Created at " + DateTime.Now.ToString(); myWorkerThread.Start(); } }