예제 #1
0
        } // main

        public void DoWork()
        {
            Thread jthread = null;

            if (_initialized == true)
            {
                double result;


                try
                {
                    for (int i = 0; i < _numthreads; i++)
                    {
                        _t1[i].Start();
                        _t2[i].Start();
                        _t3[i].Start();
                    }

                    // wait for all the threads to finish...
                    for (int j = 0; j < _numthreads; j++)
                    {
                        _t1[j].Join();
                        _t2[j].Join();
                        _t3[j].Join();
                    }

                    result = (_f.Result() + _g.Result() + _h.Result());
                    Console.Write("The result is "); Console.WriteLine(result);
                }
                catch (Exception e0)
                {
                    Console.WriteLine("Thread(s) FAILED to Start");
                }

                // start and run a thread that throws an exception
                if (_exceptionthread)
                {
                    MyException.MyException jexception;


                    jexception = new MyException.MyException(16);
                    jthread    = new Thread(new ThreadStart(jexception.Run));

                    if (jthread != null)
                    {
                        jthread.Start();
                        jthread.Join();
                    }
                }
            }
            else
            {
                throw new Exception("Threads FAILED to Initialize");
            }
        } // DoWork
예제 #2
0
파일: threads.cs 프로젝트: ArildF/masters
        } // main


        public void DoWork()
        {                         
            Thread jthread = null;
            
            if ( _initialized == true )
            {
                double result;
        
              
                try
                {                                          
                    for ( int i = 0; i < _numthreads; i++ )
                    {
                        _t1[i].Start(); 
                        _t2[i].Start(); 
                        _t3[i].Start();
                    }

                    // wait for all the threads to finish...
                    for ( int j = 0; j < _numthreads; j++ )
                    {
                        _t1[j].Join(); 
                        _t2[j].Join(); 
                        _t3[j].Join();
                    }

                    result = (_f.Result() + _g.Result() + _h.Result());
                    Console.Write( "The result is " ); Console.WriteLine( result );                                                                               
                }
                catch( Exception e0 )
                {
                    Console.WriteLine( "Thread(s) FAILED to Start" );
                }            

                // start and run a thread that throws an exception
                if ( _exceptionthread )
                {
                    MyException.MyException jexception;
                    
                    
                    jexception = new MyException.MyException( 16 );
                    jthread = new Thread( new ThreadStart( jexception.Run ) );
                     
                    if ( jthread != null )
                    {
                        jthread.Start();
                        jthread.Join(); 
                    }
                }
            }
            else
                throw new Exception( "Threads FAILED to Initialize" );

        } // DoWork