static void ThreadFailed(GThread th, Exception e)
 {
     Console.WriteLine(
         "thread # {0} finished with error '{1}'",
         th.Id,
         e.Message);
 }
        static void ThreadFinished(GThread th)
        {
            // cast GThread back to MultiplierThread
            MultiplierThread thread = (MultiplierThread)th;

            Console.WriteLine(
                "thread # {0} finished with result '{1}'",
                thread.Id,
                thread.Result);
        }
Esempio n. 3
0
        //-----------------------------------------------------------------------------------------------

        //initialises the thread on the manager
        private void SetThreadOnManager(GThread thread)
        {
            thread.SetId(++_LastThreadId);
            thread.SetApplication(this);

            Manager.Owner_SetThread(
                Credentials,
                new ThreadIdentifier(_Id, thread.Id, thread.Priority),
                Utils.SerializeToByteArray(thread));
        }
Esempio n. 4
0
 /// <summary>
 /// Gets the state of the given GThread
 /// </summary>
 /// <param name="thread"></param>
 /// <returns>ThreadState indicating its status</returns>
 internal ThreadState GetThreadState(GThread thread)
 {
     if (_Running)
     {
         return(Manager.Owner_GetThreadState(Credentials, new ThreadIdentifier(_Id, thread.Id)));
     }
     else
     {
         return(ThreadState.Unknown);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Starts the given thread indirectly by adding it to the thread buffer. When the thread buffer count reaches the thread buffer capacity then that thread buffer is sent to the manager as one thread.
        /// </summary>
        /// <param name="thread">thread</param>
        public override void StartThread(GThread thread)
        {
            lock (this)
            {
                // assign an internal thread id...
                thread.SetId(_InternalThreadId++);

                // add thread to thread buffer...
                _ThreadBuffer.Add(thread);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Fires the thread failed event.
        /// </summary>
        /// <param name="thread">thread</param>
        /// <param name="ex">exception</param>
        protected override void OnThreadFailed(GThread thread, Exception ex)
        {
            GThreadBuffer oThreadBuffer = thread as GThreadBuffer;

            if (oThreadBuffer != null)
            {
                foreach (GThread oThread1 in oThreadBuffer)
                {
                    base.OnThreadFailed(oThread1, ex);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Fires the thread failed event.
        /// </summary>
        /// <param name="oThread0">thread</param>
        /// <param name="oException">exception</param>
        protected override void OnThreadFailed(GThread oThread0, Exception oException)
        {
            GThreadBuffer oThreadBuffer = oThread0 as GThreadBuffer;

            if (oThreadBuffer != null)
            {
                foreach (GThread oThread1 in oThreadBuffer)
                {
                    base.OnThreadFailed(oThread1, oException);
                }
            }
        }
Esempio n. 8
0
        public static void JobFinished(GThread thread)
        {
            GJob job = (GJob) thread;
            Console.WriteLine("Finished job {0}", job.Id);

            foreach (FileDependency fd in job.OutputFiles)
            {
                Directory.CreateDirectory("job_" + job.Id);
                fd.Unpack(Path.Combine("job_" + job.Id, fd.FileName));
                Console.WriteLine("Unpacked file {0} for job {1}", fd.FileName, job.Id);
            }
            Console.WriteLine();
        }
Esempio n. 9
0
        //krishna added - 23May05
        //this gives more freedom to the app developer to remove the threads no longer wanted, for whatever reason
        /// <summary>
        /// Removes a GThread object from this collection IF it is in a dead / finished state.
        /// </summary>
        /// <param name="thread"></param>
        public void Remove(GThread thread)
        {
            if (thread == null)
            {
                return;
            }

            lock (InnerList)
            {
                if (thread.State == ThreadState.Dead || thread.State == ThreadState.Finished)
                    InnerList.Remove(thread);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Adds a thread to the buffer.
        /// </summary>
        /// <param name="thread">thread</param>
        public void Add(GThread oThread)
        {
            if (this.IsFull)
            {
                throw new ThreadBufferFullException("Attempting to add a thread to a full thread buffer.");
            }

            _Threads.Add(oThread);

            if (this.IsFull)
            {
                OnFull();
            }
        }
Esempio n. 11
0
        private static void App_ThreadFinish(GThread thread)
        {
            // cast the supplied GThread back to PrimeNumberChecker
            PrimeNumberChecker pnc = (PrimeNumberChecker) thread;

            // check whether the candidate is prime or not
            bool prime = false;
            if (pnc.Factors == 2) prime = true;

            // display results
            Console.WriteLine("{0} is prime? {1} ({2} factors)", pnc.Candidate, prime, pnc.Factors);

            if (prime)
                primesFound++;
        }
Esempio n. 12
0
        //krishna added - 23May05
        //this gives more freedom to the app developer to remove the threads no longer wanted, for whatever reason
        /// <summary>
        /// Removes a GThread object from this collection IF it is in a dead / finished state.
        /// </summary>
        /// <param name="thread"></param>
        public void Remove(GThread thread)
        {
            if (thread == null)
            {
                return;
            }

            lock (InnerList)
            {
                if (thread.State == ThreadState.Dead || thread.State == ThreadState.Finished)
                {
                    InnerList.Remove(thread);
                }
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Fires the thread failed event.
 /// </summary>
 /// <param name="th">thread</param>
 /// <param name="ex">ex</param>
 protected virtual void OnThreadFailed(GThread th, Exception ex)
 {
     if (ThreadFailed != null)
     {
         logger.Debug("Raising thread failed event...");
         try
         {
             ThreadFailed(th, ex); //TODO: Need to see the effect of calling it async.
         }
         catch (Exception eventhandlerEx)
         {
             logger.Debug("Error in ThreadFailed Event handler: " + eventhandlerEx);
         }
     }
 }
Esempio n. 14
0
 private void ThreadFailed(GThread th, Exception e)
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (this.rtfDisplay.InvokeRequired)
     {
         SetTextCallback2 d = new SetTextCallback2(ThreadFailed);
         this.Invoke(d, new object[] { th, e });
     }
     else
     {
         rtfDisplay.AppendText(Environment.NewLine + ":: eduGRID BotManager: " + "Error while Processing. Please rephrase and ask." + Environment.NewLine + "_________________________" + Environment.NewLine);
         rtfDisplay.ScrollToCaret();
     }
 }
Esempio n. 15
0
        //-----------------------------------------------------------------------------------------------

        /// <summary>
        /// Starts the given thread
        /// </summary>
        /// <param name="thread">thread to start</param>
        public virtual void StartThread(GThread thread)
        {
            /// May 10, 2006 [email protected]: Fix for bug 1482578
            /// Prevents the client from executing StartThread on single-use
            /// applications. StartThread should only be called for starting
            /// on-the-fly threads to multi-use applications.
            if (!_MultiUse)
            {
                throw new InvalidOperationException("Cannot use StartThread with single-use GApplication objects.");
            }

            Init();
            Threads.Add(thread);
            SetThreadOnManager(thread);
            StartGetFinishedThreads();
        }
Esempio n. 16
0
 /// <summary>
 /// Fires the thread finish event.
 /// </summary>
 /// <param name="th">thread</param>
 protected virtual void OnThreadFinish(GThread thread)
 {
     if (_ThreadFinish != null)
     {
         logger.Debug("Raising ThreadFinish event...");
         try
         {
             _ThreadFinish(thread); //TODO: Need to see the effect of calling it async.
         }
         catch (Exception eventhandlerEx)
         {
             // TODO: Figure out a way to not eat this exception!
             logger.Debug("Error in ThreadFinish event handler: " + eventhandlerEx);
         }
     }
 }
Esempio n. 17
0
        /// <summary>
        /// Fires the thread finish event.
        /// </summary>
        /// <param name="thread">thread</param>
        protected override void OnThreadFinish(GThread thread)
        {
            GThreadBuffer oThreadBuffer = thread as GThreadBuffer;

            if (oThreadBuffer != null)
            {
                foreach (GThread oThread1 in oThreadBuffer)
                {
                    Exception oException = oThreadBuffer.GetException(oThread1.Id);
                    if (oException == null)
                    {
                        base.OnThreadFinish(oThread1);
                    }
                    else
                    {
                        base.OnThreadFailed(oThread1, oException);
                    }
                }
            }
        }
Esempio n. 18
0
        //-----------------------------------------------------------------------------------------------

        //gets the finished threads
        private void GetFinishedThreads()
        {
            bool appCleanedup = false;

            logger.Info("GetFinishedThreads thread started.");
            try
            {
                int logCounter = 0;
                while (!_StopGetFinished)
                {
                    try
                    {
                        //a couple of potential issues here:
                        //1. the first and second calls may return different thread counts.
                        //since more threads may finish meanwhile.
                        //2. this sleeps for 700 ms ... which means really quick threads can't
                        //be retrieved before 700ms.
                        Thread.Sleep(700);

                        byte[][] FinishedThreads = Manager.Owner_GetFinishedThreads(Credentials, _Id);
                        _NumThreadsFinished = Manager.Owner_GetFinishedThreadCount(Credentials, _Id);

                        if (logCounter > 20 || FinishedThreads.Length > 0)
                        {
                            //print log only once in a while
                            logger.Debug("Threads finished this poll..." + FinishedThreads.Length);
                            logger.Debug("Total Threads finished so far..." + _NumThreadsFinished);
                            logCounter = 0;
                        }
                        logCounter++;

                        for (int i = 0; i < FinishedThreads.Length; i++)
                        {
                            GThread th = (GThread)Utils.DeserializeFromByteArray(FinishedThreads[i]);
                            // assign [NonSerialized] members from the old local copy
                            th.SetApplication(this);
                            // HACK: need to change this if the user is allowed to set the id
                            _Threads[th.Id] = th;
                            //RemoteException rex = Manager.Owner_GetFailedThreadException(Credentials, new ThreadIdentifier(_Id, th.Id));
                            //Exception ex = new Exception(rex.Message);
                            Exception       ex  = Manager.Owner_GetFailedThreadException(Credentials, new ThreadIdentifier(_Id, th.Id));
                            RemoteException rex = ex as RemoteException;
                            if (rex != null)
                            {
                                ex = rex.OriginalRemoteException;
                            }

                            if (ex == null)
                            {
                                logger.Debug("Thread completed successfully:" + th.Id);
                                //raise the thread finish event
                                OnThreadFinish(th);
                            }
                            else
                            {
                                logger.Debug("Thread failed:" + th.Id);
                                //raise the thread failed event
                                OnThreadFailed(th, ex);
                            }
                        }

                        // May 10, 2006 [email protected]: Fix for bug 1485426
                        if ((!_MultiUse) && (_NumThreadsFinished == Threads.Count))
                        {
                            logger.Debug("Application finished!" + _Id);

                            if (!appCleanedup)
                            {
                                //clean up manager,executor.
                                logger.Debug("SingleUse-Application finished cleaning up..." + _Id);
                                Manager.Owner_CleanupApplication(Credentials, _Id);
                                appCleanedup = true;
                            }
                            if (_ApplicationFinish != null)
                            {
                                /// January 25, 2006 [email protected]: Fix for bug 1410797
                                /// Mark the application as stopped in the database
                                /// This relies on the client to mark the application as stopped on the server,
                                /// maybe not the best approach
                                Manager.Owner_StopApplication(Credentials, _Id);

                                logger.Debug("Raising AppFinish event (for single-use app)..." + _Id);
                                _Running = false;
                                try
                                {
                                    _ApplicationFinish.BeginInvoke(null, null);
                                }
                                catch (Exception ex)
                                {
                                    logger.Debug("ApplicationFinish Event-handler error: " + ex.ToString());
                                }
                            }
                            break;
                            //we break here since there is no point raising events mutliple times.!!! :kna: dec 3, 2006.
                            //logger.Debug("App finished, but still looping since some-one might subscribe to this event, and we can send it to them now.");
                        }
                    }
                    catch (SocketException se)
                    {
                        // lost connection to Manager
                        logger.Error("Lost connection to manager. Stopping GetFinishedThreads...", se);
                        break;
                    }
                    catch (RemotingException re)
                    {
                        // lost connection to Manager
                        logger.Error("Lost connection to manager. Stopping GetFinishedThreads...", re);
                        break;
                    }
                    catch (Exception e)
                    {
                        logger.Error("Error in GetFinishedThreads. Continuing to poll for finished threads...", e);
                    }
                }
            }
            catch (ThreadAbortException)
            {
                logger.Debug("GetFinishedThreads Thread aborted.");
                Thread.ResetAbort();
            }
            catch (Exception e)
            {
                logger.Error("Error in GetFinishedThreads. GetFinishedThreads thread stopping...", e);
            }

            logger.Info("GetFinishedThreads thread exited...");
        }
Esempio n. 19
0
        void UpdateBitmap0(GThread thread)
        {
            // update progress bar
            if (pb.Value + 1 <= pb.Maximum)
            {
                pb.Value++;
            }

            // update status bar
            sb.Text = (DateTime.Now - startTime).ToString();

            MandelThread mandel = (MandelThread) thread;
            int startX = mandel.MapNumX * mandel.Width;
            int startY = mandel.MapNumY * mandel.Height;

            for (int x=0; x<mandel.Width; x++)
            {
                for (int y=0; y<mandel.Height; y++)
                {
                    map.SetPixel(x+startX, y+startY, mandel.Map.GetPixel(x, y));
                }
            }
            pictureBox1.Refresh();
        }
Esempio n. 20
0
 private void ThreadFinished(GThread th)
 {
     // cast GThread back to eduGRID_Thread
     eduGRID_Thread thread = (eduGRID_Thread)th;
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (this.rtfDisplay.InvokeRequired)
     {
         SetTextCallback d = new SetTextCallback(ThreadFinished);
         this.Invoke(d, new object[] { th });
     }
     else
     {
         rtfDisplay.AppendText(Environment.NewLine + ":: Bot: ");
         rtfDisplay.ScrollToCaret();
         rtfDisplay.AppendText(thread.Result + Environment.NewLine + "_________________________" + Environment.NewLine);
     }
 }
Esempio n. 21
0
 /// <summary>
 /// Fires the thread failed event.
 /// </summary>
 /// <param name="thread">thread</param>
 /// <param name="ex">exception</param>
 protected override void OnThreadFailed(GThread thread, Exception ex)
 {
     GThreadBuffer oThreadBuffer = thread as GThreadBuffer;
     if (oThreadBuffer != null)
     {
         foreach (GThread oThread1 in oThreadBuffer)
         {
             base.OnThreadFailed(oThread1, ex);
         }
     }
 }
Esempio n. 22
0
 //-----------------------------------------------------------------------------------------------
 /// <summary>
 /// Adds a GThread object to this collection
 /// </summary>
 /// <param name="thread">the grid thread to add</param>
 public void Add(GThread thread)
 {
     InnerList.Add(thread);
 }
Esempio n. 23
0
 private void ThreadFailed(GThread th, Exception e)
 {
     Append_Text("Bot: " + "Failed to acquire result.");
 }
Esempio n. 24
0
 private void ThreadFailed(GThread th, Exception e)
 {
 }
Esempio n. 25
0
 private void ga_ThreadFailed(GThread thread, Exception e)
 {
     //to prevent multiple events from over-writing each other
     lock (threadCompleteLock)
     {
         logger.Debug("Thread failed: " + thread.Id + "\n" + e.ToString());
         UpdateStatus();
         printStdFiles(thread as RenderThread);
     }
 }
Esempio n. 26
0
        static void ThreadFinished(GThread thread)
        {
            th++;
            Console.WriteLine("grid thread # {0} finished executing", thread.Id);

            //			if (th > 1)
            //			{
            //				Console.WriteLine("For testing aborting threads beyond th=5");
            //				try
            //				{
            //					Console.WriteLine("Aborting thread th=" + th);
            //					thread.Abort();
            //					Console.WriteLine("DONE Aborting thread th=" + th);
            //				}
            //				catch (Exception e)
            //				{
            //					Console.WriteLine(e.ToString());
            //				}
            //			}
        }
Esempio n. 27
0
 private void ga_ThreadFinish(GThread thread)
 {
     //to prevent multiple events from over-writing each other
     lock (threadCompleteLock)
     {
         logger.Debug("Thread finished: " + thread.Id);
         UpdateStatus();
         unpackThread(thread);
         printStdFiles(thread as RenderThread);
     }
 }
Esempio n. 28
0
 private void unpackThread(GThread thread)
 {
     RenderThread rth = (RenderThread)thread;
     if (rth!=null)
     {
         Bitmap bit = rth.RenderedImageSegment;
         if (bit!=null)
         {
             logger.Debug("Loading from bitmap");
             displayImage(bit, rth.Col, rth.Row);
         }
         else
         {
             logger.Debug ("bit is null! " + thread.Id );
         }
     }
 }
Esempio n. 29
0
        private void ThreadFinished(GThread th)
        {
            //            double min = Double.MaxValue;
            //            double mintest = Double.MaxValue;
            double min_local = Double.MaxValue;
            double mintest_local = Double.MaxValue;
            lock (this)
            {
                foreach (double d in (th as SingleNNTraining).Errors)
                {
                    if (d < min_local)
                    {
                        min_local = d;
                    }
                }

                if (min_local < min)
                {
                    min = min_local;
                    mBestActivationNetwork = (th as SingleNNTraining).Network;
                }

                if (mintest > (th as SingleNNTraining).MinTestError)
                {
                    mintest = (th as SingleNNTraining).MinTestError;
                    mBestTestActivationNetwork = (th as SingleNNTraining).TestBestNetwork;
                }
            }

            NNResultSet single_result = new NNResultSet();
            single_result.Error = min_local;
            results.Add(single_result);

            ResultsAddItemsCaller res = new ResultsAddItemsCaller(ResultsAddItems);
            lbResults.Invoke(res, String.Format("{0} {1}", min_local, (th as SingleNNTraining).MinTestError));

            RefreshVisualStatus refresh_status = new RefreshVisualStatus(DoRefreshVisualStatus);
            this.Invoke(refresh_status);
            ReinitsFinished++;
        }
Esempio n. 30
0
 private void ThreadFailed(GThread th, Exception e)
 {
     MessageBox.Show(String.Format("thread # {0} finished with error '{1}'",
         th.Id,
         e.Message));
 }
Esempio n. 31
0
        //-----------------------------------------------------------------------------------------------
        //initialises one thread on the manager
        private void SetThreadOnManager(GThread thread)
        {
            thread.SetId(++_LastThreadId);
            thread.SetApplication(this);

            Manager.Owner_SetThread(
                Credentials,
                new ThreadIdentifier(_Id, thread.Id, thread.Priority),
                Utils.SerializeToByteArray(thread));
        }
Esempio n. 32
0
 public void ThreadFinished(GThread th)
 {
     // cast GThread back to eduGRID_Thread
     eduGRID_Thread thread = (eduGRID_Thread)th;
 }
Esempio n. 33
0
        /// <summary>
        /// Starts the given thread indirectly by adding it to the thread buffer. When the thread buffer count reaches the thread buffer capacity then that thread buffer is sent to the manager as one thread.
        /// </summary>
        /// <param name="oThread">thread</param>
        public override void StartThread(GThread oThread)
        {
            lock (this)
            {
                // assign an internal thread id...
                oThread.SetId(m_nInternalThreadId++);

                // add thread to thread buffer...
                m_oThreadBuffer.Add(oThread);
            }
        }
Esempio n. 34
0
        /// <summary>
        /// Adds a thread to the buffer.
        /// </summary>
        /// <param name="thread">thread</param>
        public void Add(GThread oThread)
        {
            if (this.IsFull)
            {
                throw new ThreadBufferFullException("Attempting to add a thread to a full thread buffer.");
            }

            _Threads.Add(oThread);

            if (this.IsFull)
            {
                OnFull();
            }
        }
Esempio n. 35
0
 /// <summary>
 /// Fires the thread failed event.
 /// </summary>
 /// <param name="oThread0">thread</param>
 /// <param name="oException">exception</param>
 protected override void OnThreadFailed(GThread oThread0, Exception oException)
 {
     GThreadBuffer oThreadBuffer = oThread0 as GThreadBuffer;
     if (oThreadBuffer != null)
     {
         foreach (GThread oThread1 in oThreadBuffer)
         {
             base.OnThreadFailed(oThread1, oException);
         }
     }
 }
Esempio n. 36
0
        private void ThreadFinished(GThread th)
        {
            // cast GThread back to eduGRID_Thread
            eduGRID_Thread thread = (eduGRID_Thread)th;
            Append_Text("Bot: " + thread.Result);
            //chat_Display.AppendText("Bot: " + thread.Result);

            if (enableSpeechOutputToolStripMenuItem.Checked)
            {
                SpVoice objSpeech = new SpVoice();
                objSpeech.Rate = 1;
                objSpeech.Speak(thread.Result, SpeechVoiceSpeakFlags.SVSFlagsAsync);
                //objSpeech.SynchronousSpeakTimeout = 20;

            }
        }
Esempio n. 37
0
 /// <summary>
 /// Fires the thread finish event.
 /// </summary>
 /// <param name="oThread0">thread</param>
 protected override void OnThreadFinish(GThread oThread0)
 {
     GThreadBuffer oThreadBuffer = oThread0 as GThreadBuffer;
     if (oThreadBuffer != null)
     {
         foreach (GThread oThread1 in oThreadBuffer)
         {
             Exception oException = oThreadBuffer.GetException(oThread1.Id);
             if (oException == null)
             {
                 base.OnThreadFinish(oThread1);
             }
             else
             {
                 base.OnThreadFailed(oThread1, oException);
             }
         }
     }
 }
Esempio n. 38
0
 /// <summary>
 /// Gets the state of the given GThread
 /// </summary>
 /// <param name="thread"></param>
 /// <returns>ThreadState indicating its status</returns>
 internal ThreadState GetThreadState(GThread thread)
 {
     if (_Running)
     {
         return Manager.Owner_GetThreadState(Credentials, new ThreadIdentifier(_Id, thread.Id));
     }
     else
     {
         return ThreadState.Unknown;
     }
 }
Esempio n. 39
0
 static void ThreadFinished(GThread th)
 {
     var thread = (IntegralCalculationThread)th;
     sum += thread.Result;
 }
Esempio n. 40
0
        //-----------------------------------------------------------------------------------------------
        /// <summary>
        /// Starts the given thread
        /// </summary>
        /// <param name="thread">thread to start</param>
        public virtual void StartThread(GThread thread)
        {
            if (thread == null)
                throw new ArgumentNullException("thread", "GThread cannot be null.");

            /// May 10, 2006 [email protected]: Fix for bug 1482578
            /// Prevents the client from executing StartThread on single-use
            /// applications. StartThread should only be called for starting
            /// on-the-fly threads to multi-use applications.
            if (!_MultiUse)
            {
                throw new InvalidOperationException("Cannot use StartThread with single-use GApplication objects.");
            }

            Init();
            Threads.Add(thread);
            SetThreadOnManager(thread);
            StartGetFinishedThreads();
        }
Esempio n. 41
0
 /// <summary>
 /// Fires the thread finish event.
 /// </summary>
 /// <param name="th">thread</param>
 protected virtual void OnThreadFinish(GThread thread)
 {
     if (_ThreadFinish != null)
     {
         logger.Debug("Raising ThreadFinish event...");
         try
         {
             _ThreadFinish(thread); //TODO: Need to see the effect of calling it async.
         }
         catch (Exception eventhandlerEx)
         {
             // TODO: Figure out a way to not eat this exception!
             logger.Debug("Error in ThreadFinish event handler: " + eventhandlerEx);
         }
     }
 }
Esempio n. 42
0
 //-----------------------------------------------------------------------------------------------
 /// <summary>
 /// Aborts the given thread
 /// </summary>
 /// <param name="thread">thread to abort</param>
 internal void AbortThread(GThread thread)
 {
     if (_Running)
     {
         Manager.Owner_AbortThread(Credentials, new ThreadIdentifier(_Id, thread.Id));
     }
 }
Esempio n. 43
0
        //-----------------------------------------------------------------------------------------------

        /// <summary>
        /// Adds a GThread object to this collection
        /// </summary>
        /// <param name="thread">the grid thread to add</param>
        public void Add(GThread thread)
        {
            InnerList.Add(thread);
        }