コード例 #1
0
        void _AddValue(string key1, object key2, GlobalNotificationDelegate val)
        {
            var objDic = ValueOrDefault(_dic, key1);

            if (objDic == null)
            {
                objDic = _dic[key1] = new Dictionary <object, GlobalNotificationDelegate>();
            }

            var res = ValueOrDefault(objDic, key2);

            if (res == null)
            {
                objDic[key2] = val;
            }
            else
            {
                objDic[key2] = objDic[key2] + val;
            }
        }
コード例 #2
0
        public void Register(string name, object target, GlobalNotificationDelegate action, bool mainThread = false)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }


            lock (_locker)
            {
                _AddValue(name, target, action);
            }
        }
コード例 #3
0
        bool _RemoveValue(string key1, object key2, GlobalNotificationDelegate val)
        {
            var objDic = ValueOrDefault(_dic, key1);

            if (objDic == null)
            {
                return(false);
            }

            var res = ValueOrDefault(objDic, key2);

            if (res == null)
            {
                return(false);
            }
            else
            {
                objDic[key2] = objDic[key2] - val;
            }
            return(true);
        }
コード例 #4
0
        void _AddValue(string key1, object key2, GlobalNotificationDelegate val)
        {
            //从总的dic中取出该消息的所有注册
            var objDic = ValueOrDefault(_dic, key1);

            if (objDic == null) //如果没有注册,则新增加一个
            {
                objDic = _dic[key1] = new Dictionary <object, GlobalNotificationDelegate>();
            }

            var res = ValueOrDefault(objDic, key2); //从该消息中找到某个target的设置

            if (res == null)                        //如果这个target没有设置 则设置上去
            {
                objDic[key2] = val;
            }
            else
            {
                objDic[key2] = objDic[key2] + val;
            }
        }
コード例 #5
0
        public bool Unregister(string name, object target = null, GlobalNotificationDelegate action = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            lock (_locker)
            {
                if (action != null)
                {
                    return(_RemoveValue(name, target, action));
                }

                if (target != null)
                {
                    return(_RemoveKey(name, target));
                }

                return(_RemoveKey(name));
            }
        }
コード例 #6
0
        public static void DispatcherRun(Dispatcher dispatcher, GlobalNotificationDelegate action, GlobalNotificationMessage msg)
        {
            GlobalNotificationDelegate func = new GlobalNotificationDelegate(action);

            dispatcher.BeginInvoke(func, msg);
        }