예제 #1
0
        /// <summary>
        /// Finalises all ThreadManager objects
        ///
        /// Called once at finish
        /// </summary>
        public static void Finalise()
        {
            if (_cpuUsage == null)
            {
                throw new InvalidOperationException("ThreadManager must be initialised");
            }

            CancelAll();

            if (_threadManager != null)
            {
                _threadManager.CancelThread();
                _threadManager = null;
            }

            if (_threadAbortManager != null)
            {
                _threadAbortManager.CancelThread();
                _threadAbortManager = null;
            }

            if (_threadCacheManager != null)
            {
                _threadCacheManager.CancelThread();
                _threadCacheManager = null;
            }

            _cpuUsage = null;
        }
예제 #2
0
        public static void Initialise(ICpuUsage cpuUsage)
        {
            // only initialize once
            if (_cpuUsage != null)
            {
                return;
            }

            _cpuUsage = cpuUsage ?? throw new ArgumentNullException(nameof(cpuUsage));

            using (TimedLock.Lock(_lockObject))
            {
                _globalCancelRequested = false;

                if (_threadManager == null)
                {
                    _threadManager = new ThreadManagerManager();
                    ThreadStart(_threadManager, "Thread Manager - Management Thread", ThreadPriority.BelowNormal, false);
                }


                if (_threadAbortManager == null)
                {
                    _threadAbortManager = new ThreadAbortManager();
                    ThreadStart(_threadAbortManager, "Thread Abort - Management Thread", ThreadPriority.Lowest, false);
                }


                if (_threadCacheManager == null)
                {
                    _threadCacheManager = new ThreadCacheManager();
                    Classes.ThreadManager.ThreadStart(_threadCacheManager,
                                                      "Cache Management Thread", ThreadPriority.Lowest);
                }
            }
        }