Exemplo n.º 1
0
        /// <summary>
        /// Change the state.
        /// </summary>
        public void SetState
        (
            bool newState
        )
        {
            Log.Trace
            (
                nameof(BusyState) + "::" + nameof(SetState)
                + ": newState="
                + newState
            );

            lock (_lock)
            {
                if (newState != _currentState)
                {
                    if (newState)
                    {
                        _waitHandle.Reset();
                        _thread = Thread.CurrentThread;
                    }
                    else
                    {
                        _waitHandle.Set();
                    }

                    _currentState = newState;

                    if (UseAsync)
                    {
                        StateChanged.RaiseAsync(this);
                    }
                    else
                    {
                        StateChanged.Raise(this);
                    }
                }
            }
        }