Exemplo n.º 1
0
		public override Object Execute(Object o, IList args)
		{			
			// the runner will automatically kill the thread on disposal
			using(ThreadCollectionRunner runner = new ThreadCollectionRunner())
			{			
				// create threads
				ArrayList starters = new ArrayList();
				for(int i = 0;i<this.Count;++i)
				{
					// run test
					ThreadedRunInvokerStarter starter = new ThreadedRunInvokerStarter(
						this.Invoker,
						o,
						args
						);
					starters.Add(starter);
					runner.Threads.Add(new ThreadStart(starter.Run));
				}
			
				// launch
				runner.StartAll();
				runner.WaitForFinishingSafe();

                // Now that we are done running, check to see if any exceptions were thrown.
                // NOTE: This only reports the first thread that failed.
                foreach ( ThreadedRunInvokerStarter starter in starters )
                {
                    if ( starter.HasThrown )
                    {
                        throw new Exception( "Runner throwed.", starter.Exception );
                    }
                }
			}

			return null;
        }
        public override Object Execute(Object o, IList args)
        {
            // the runner will automatically kill the thread on disposal
            using(ThreadCollectionRunner runner = new ThreadCollectionRunner())
            {
                // create threads
                ArrayList starters = new ArrayList();
                for(int i = 0;i<this.Count;++i)
                {
                    // run test
                    ThreadedRunInvokerStarter starter = new ThreadedRunInvokerStarter(
                        this.Invoker,
                        o,
                        args
                        );
                    starters.Add(starter);
                    runner.Threads.Add(new ThreadStart(starter.Run));
                }

                // launch
                runner.StartAll();
                while(runner.AnyAlive)
                {
                    foreach(ThreadedRunInvokerStarter starter in starters)
                    {
                        if (starter.HasThrown)
                        {
                            runner.WaitForFinishingSafe();
                            throw new Exception("Runner throwed.",starter.Exception);
                        }
                    }
                }
            }

            return null;
        }