Пример #1
0
        /// <summary>
        /// Removes the thread.
        /// </summary>
        /// <param name="tInfo">The t information.</param>
        public void RemoveThread(ThreadWatcherInfo tInfo)
        {
            if (tInfo.MaxAliveWindow == TimeSpan.Zero || WorkManagerConfig.DisableWatchWhenDebugging)
            {
                return;
            }

            lock (_threads)
            {
                _threads.Remove(tInfo);
            }
        }
Пример #2
0
        /// <summary>
        /// Adds the thread.
        /// </summary>
        /// <param name="tInfo">The t information.</param>
        public void AddThread(ThreadWatcherInfo tInfo)
        {
            if (tInfo.MaxAliveWindow == TimeSpan.Zero || WorkManagerConfig.DisableWatchWhenDebugging)
            {
                return;
            }

            lock (_threads)
            {
                _threads.Add(tInfo);
                tInfo.LastResponseTime = DateTime.Now;
            }
        }
Пример #3
0
        /// <summary>
        /// Passives the sleep.
        /// </summary>
        /// <param name="tInfo">The t information.</param>
        /// <param name="mSec">The m sec.</param>
        /// <param name="terminate">if set to <c>true</c> [terminate].</param>
        public static void PassiveSleep(ThreadWatcherInfo tInfo, long mSec, ref bool terminate)
        {
            var sleep = mSec;

            while ((sleep > 0) && !terminate)
            {
                tInfo.LastResponseTime = DateTime.Now;

                Thread.Sleep(100);
                sleep -= 100;
            }

            tInfo.LastResponseTime = DateTime.Now;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseWorker"/> class.
        /// </summary>
        /// <param name="workPackage">The work package.</param>
        /// <exception cref="WorkManagerException"></exception>
        public BaseWorker(IWorkPackage workPackage) : base(workPackage.NameInstance)
        {
            try
            {
                WorkPackage                      = workPackage;
                Name                             = WorkPackage.NameInstance;
                Notification                     = WorkPackage.WorkManager.Notification;
                _restartAbortedThread            = false;
                _abortThreadOnUnhandledException = WorkPackage.Parameters("abortThreadOnUnhandledException", "false") == "true";
                _restartNonResponsive            = WorkPackage.Parameters("restartNonResponsive", "false") == "true";
                _workSleep                       = int.Parse(WorkPackage.Parameters("workSleep", "60000"));
                _threadWatcherInfo               = new ThreadWatcherInfo(this, int.Parse(WorkPackage.Parameters("aliveResponseWindow", "0")));

                OnInitialize();
            }
            catch (Exception ex)
            {
                var eMsg = string.Format("Initialize failed: An unhandled exception was detected in Thread '{0} -> {1}'.", Name, ex.Message);
                throw new WorkManagerException(eMsg, ex);
            }
        }
Пример #5
0
 /// <summary>
 /// Removes the non responsive worker.
 /// </summary>
 /// <param name="tInfo">The t information.</param>
 internal void RemoveNonResponsiveWorker(ThreadWatcherInfo tInfo)
 {
     _messageManager.SendMessage(MessageManagerId.WorkerFailedToRespond, tInfo);
 }