Example #1
0
        /// <summary>
        /// Start the active object. This will not return until the thread
        /// </summary>
        /// <remarks>If already running, will do nothing.</remarks>
        public void Start()
        {
            lock (this._lock)
            {
                if (!this.Running && this._thread == null)
                {
                    this.Running = true;

                    _thread = new Thread(new ThreadStart(this.Bootstrap));
                    _thread.Start();

                    MonitorMicro.Wait(this._lock);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Stop the active object. This will not return until the thread has joined.
        /// </summary>
        public void Stop()
        {
            lock (this._lock)
            {
                if (this.Running)
                {
                    this.Running = false;

                    MonitorMicro.Pulse(this._lock);
                }
            }

            if (_thread != null)
            {
                _thread.Join();
                _thread = null;
            }
        }
Example #3
0
        /// <summary>
        /// Bootstrapper to enable the start method to return.
        /// </summary>
        private void Bootstrap()
        {
            lock (this._lock)
            {
                // enable the start method to return
                MonitorMicro.Pulse(_lock);
            }


            try
            {
                this.Run();
            }
            finally // ensure running is reset to false
            {
                this.Running = false;
            }
        }