示例#1
0
        // 尝试答复此界面消息(引发回调方法)。
        internal bool TryReply()
        {
            bool result = false;

            if (_NeedReply)
            {
                UIMessageState state = State;

                if (state != UIMessageState.Discarded || (state == UIMessageState.Discarded && _ReplyWhenDiscarded))
                {
                    _ReplyLock.EnterWriteLock();

                    try
                    {
                        ReplyTime = DateTime.Now;

                        _Sender.Invoke(_CallbackMethod, _Sender, this);

                        result = true;
                    }
                    finally
                    {
                        _ReplyLock.ExitWriteLock();
                    }
                }
            }

            return(result);
        }
示例#2
0
        private object _ReplyData;   // 此界面消息的答复数据。

        //

        // 尝试更新此界面消息的状态。
        internal bool TryUpdateState(UIMessageState state)
        {
            _StateLock.EnterWriteLock();

            try
            {
                switch ((((long)_State) << 32) | (long)state)
                {
                case (((long)UIMessageState.Created) << 32) | (long)UIMessageState.WaitingToProcess:
                {
                    _RequestTime = DateTime.Now;
                    _State       = state;
                }
                    return(true);

                case (((long)UIMessageState.WaitingToProcess) << 32) | (long)UIMessageState.Processing:
                {
                    _ProcessStartTime = DateTime.Now;
                    _State            = state;
                }
                    return(true);

                case (((long)UIMessageState.WaitingToProcess) << 32) | (long)UIMessageState.Discarded:
                {
                    _ProcessStartTime  = DateTime.Now;
                    _ProcessFinishTime = DateTime.Now;
                    _State             = state;
                }
                    return(true);

                case (((long)UIMessageState.Processing) << 32) | (long)UIMessageState.ProcessCompleted:
                {
                    _ProcessFinishTime = DateTime.Now;
                    _State             = state;
                }
                    return(true);

                case (((long)UIMessageState.Processing) << 32) | (long)UIMessageState.ProcessFailed:
                {
                    _ProcessFinishTime = DateTime.Now;
                    _State             = state;
                }
                    return(true);

                default:
                    return(false);
                }
            }
            finally
            {
                _StateLock.ExitWriteLock();
            }
        }
示例#3
0
        /// <summary>
        /// 使用消息码初始化 UIMessage 的新实例。
        /// </summary>
        /// <param name="messageCode">消息码。</param>
        public UIMessage(int messageCode)
        {
            _UidLock.EnterWriteLock();

            try
            {
                _Uid = unchecked (_CurrentMaxUid + 1);

                if (_Uid > _MaxUid || _Uid < _MinUid)
                {
                    _Uid = _MinUid;
                }

                _CurrentMaxUid = _Uid;
            }
            finally
            {
                _UidLock.ExitWriteLock();
            }

            //

            _MessageCode = messageCode;

            _AllowAsync         = false;
            _AllowDiscard       = false;
            _NeedReply          = false;
            _ReplyWhenDiscarded = false;
            _Sender             = null;
            _CallbackMethod     = null;

            //

            _CreateTime        = DateTime.Now;
            _RequestTime       = DateTime.MaxValue;
            _ProcessStartTime  = DateTime.MaxValue;
            _ProcessFinishTime = DateTime.MaxValue;
            _ReplyTime         = DateTime.MaxValue;

            _State = UIMessageState.Created;

            _Exception = null;

            //

            _RequestData = null;
            _ReplyData   = null;
        }