Пример #1
0
        /// <summary>
        ///     Invoked when obj started
        /// </summary>
        protected override void OnStart()
        {
            base.OnStart();

            Scheduler          = new TimerScheduler(this);
            CoroutineScheduler = New <CoroutineScheduler>(new ObjArg(this));
            CoroutineScheduler.Start();

            if (_workingQueue != null ||
                _workingThread != null)
            {
                Logger.Ins.Fatal("AutoXService being start more than once");
                return;
            }

            _workingQueue  = new BlockingCollection <IJob>(QueueCapacity);
            _workingThread = new Thread(WorkingProcedure)
            {
                Name = "AutoXService", IsBackground = true
            };
            // use background thread
            // see http://msdn.microsoft.com/en-us/library/h339syd0.aspx

            _workingThread.Start();
            Logger.Ins.Debug("Auto logic service started!");
        }
Пример #2
0
        /// <summary>
        ///     internal called when an Obj is to be destroyed
        /// </summary>
        protected override void OnDestroy()
        {
            base.OnDestroy();

            Scheduler.Dispose();
            CoroutineScheduler.Destroy();

            if (_workingThread == null ||
                _workingQueue == null)
            {
                Logger.Ins.Fatal("AutoXService not yet been started");
                return;
            }

            _stopWorking = true;
            _workingThread.Join();
            Logger.Ins.Debug("auto-Service stopped!");
        }