Beispiel #1
0
        public static IForeverThread New(Action callback, ILogFile log = null, ForeverThreadConfig config = null)
        {
            log = log ?? LogFile.Console;
            config = config ?? new ForeverThreadConfig();

            return
                new ForeverThread(callback, log, config);
        }
Beispiel #2
0
        private ForeverThread(Action callback, ILogFile log, ForeverThreadConfig config)
        {
            _log = log;

            int count = Interlocked.Increment(ref _threadCounter);

            if (config == null)
            {
                config = new ForeverThreadConfig();
            }

            _config = new ForeverThreadConfig
                {
                    Name = config.Name ?? "ForeverThread.{0}".Fmt(count),
                    StartTimeout = config.StartTimeout,
                    StopTimeout = config.StopTimeout
                };

            _stopRequestCount = 0;
            _isStartedEvent = new ManualResetEvent(false);
            _isStoppedEvent = new ManualResetEvent(false);
            _thr = new Thread(() => thread_loop(callback));
        }