Пример #1
0
        public void Run()
        {
            workerThread = null;
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                using (FixtureWorker worker = new FixtureWorker(this))
                {
                    workerThread = new Thread(new ThreadStart(worker.RunAsync));
                    workerThread.SetApartmentState(this.Fixture.Apartment);
                    workerThread.IsBackground = true;
                    workerThread.Priority     = ThreadPriority.Lowest;

                    int timeOut =
                        (this.Fixture.TimeOut == int.MaxValue)
                            ? int.MaxValue : 60 * 1000 * this.Fixture.TimeOut;
                    // if a debugger is attached, no time out
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        timeOut = int.MaxValue;
                    }

                    workerThread.Start();
                    if (!workerThread.Join(timeOut))
                    {
                        // cancel and wait for 10 sec
                        worker.CancelAsync();
                        if (!workerThread.Join(10 * 1000))
                        {
                            this.AbortWorkerThread();
                        }

                        // store result
                        TestResult result = new TestResult(Fixture.Name, "FixtureTimedOut");
                        result.Start();
                        result.Fail(new FixtureTimedOutException(this.Fixture.Name));
                        this.TestListener.FixtureTearDown(result);
                    }
                    else
                    {
                        if (worker.UnhandledException != null)
                        {
                            throw new ApplicationException("Exception is runner", worker.UnhandledException);
                        }
                    }
                }
            }
            finally
            {
                this.AbortWorkerThread();
            }
        }
        public void Run()
        {
            workerThread = null;
            System.Runtime.CompilerServices.RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                using (FixtureWorker worker = new FixtureWorker(this))
                {
                    workerThread = new Thread(new ThreadStart(worker.RunAsync));
                    workerThread.SetApartmentState(this.Fixture.Apartment);
                    workerThread.IsBackground = true;
                    workerThread.Priority = ThreadPriority.Lowest;

                    int timeOut = 
                        (this.Fixture.TimeOut==int.MaxValue) 
                            ? int.MaxValue : 60 * 1000 * this.Fixture.TimeOut;
                    // if a debugger is attached, no time out
                    if (System.Diagnostics.Debugger.IsAttached)
                        timeOut = int.MaxValue;

                    workerThread.Start();
                    if (!workerThread.Join(timeOut))
                    {
                        // cancel and wait for 10 sec
                        worker.CancelAsync();
                        if (!workerThread.Join(10 * 1000))
                            this.AbortWorkerThread();

                        // store result
                        TestResult result = new TestResult(Fixture.Name, "FixtureTimedOut");
                        result.Start();
                        result.Fail(new FixtureTimedOutException(this.Fixture.Name));
                        this.TestListener.FixtureTearDown(result);
                    }
                    else
                    {
                        if (worker.UnhandledException != null)
                            throw new ApplicationException("Exception is runner", worker.UnhandledException);
                    }
                }
            }
            finally
            {
                this.AbortWorkerThread();
            }
        }