Пример #1
0
        /// <summary>
        /// Thread loop for the real-time worker.
        /// </summary>
        private void RealTimeThreadMain()
        {
            // set the name for vs.net debugging
            Thread.CurrentThread.Name = "Real Time Worker";

            // TODO: allow shutdown politely to be registered with ThreadManager and have it call stop
            ThreadManager.Current.Register(Thread.CurrentThread);

            try
            {
                try
                {
                    // work until it's quittin' time
                    while (Running)
                    {
                        IKernelTask nextTask;
                        if (_realTimeWork.Dequeue(out nextTask))
                        {
                            try
                            {
                                nextTask.RunTask();
#if DEBUG_TASKS
                                Util.LPConsole.WriteLine("Real Time Worker", nextTask.ToString());
#endif
                            }
                            catch (Exception ex)
                            {
                                Session.UserSession.Current.Console.Add("UNCAUGHT EXCEPTION IN TASK: " + ex.Message, "Kernel");
                            }
                        }
                        else if (_realTimeWork.Enabled)
                        {
                            _realTimeWork.BlockForWork();
                        }
                    }
                }
                catch (ThreadAbortException)
                {
                }
                catch (Exception ex)
                {
                    Session.UserSession.Current.Console.Add("KERNEL PANIC: " + ex.Message, "Kernel");
                }
            }
            finally
            {
                ThreadManager.Current.Unregister(Thread.CurrentThread);
            }
        }
Пример #2
0
 public Task Scan()
 {
     Stopped.Value = false;
     return(Task.Factory.StartNew(state =>
     {
         if (!((InternalStop)state).Value)
         {
             BacklogQueue.Scan();
             InProcessQueue.Scan(); // for directly insert data to db
             if (_firstRun)
             {
                 _firstRun = false;
                 RealTimeQueue.Scan();
                 EmailMessage message;
                 while (!((InternalStop)state).Value && RealTimeQueue.Dequeue(out message))
                 {
                     InProcessQueue.Enqueue(message);
                 }
             }
         }
     }, Stopped, TaskCreationOptions.AttachedToParent));
 }