Exemplo n.º 1
0
        protected static bool _notifyEvent(EventPairDic dic, EventObjList list, string eventName, params object[] args)
        {
            monitorEnter(dic);

            EventPairList _list = null;

            if (!dic.TryGetValue(eventName, out _list))
            {
                //if (dic == sDicToMain)
                //{
                //    LogFile.Warn("sDicToMain do not have event named \"" + eventName + "\"");
                //}
                //else
                //{
                //    LogFile.Warn("sDicToThread do not have event named \"" + eventName + "\"");
                //}
                monitorExit(dic);

                return(false);
            }

            foreach (Pair item in _list)
            {
                EventObj _obj = new EventObj();
                _obj.info = item;
                _obj.args = args;
                list.AddLast(_obj);
            }

            monitorExit(dic);

            return(true);
        }
Exemplo n.º 2
0
        protected static bool _registerEvent(EventPairDic dic, string eventName, object obj, string funcName)
        {
            _deregisterEvent(dic, eventName, obj);

            Pair pair = new Pair();

            pair.obj       = obj;
            pair.eventName = eventName;
            pair.method    = obj.GetType().GetMethod(funcName);
            if (null == pair.method)
            {
                LogFile.Warn("Register worning: Obj(" + obj + ") do not have method named \"" + funcName + "\"");
                return(false);
            }

            EventPairList list = null;

            monitorEnter(dic);

            if (!dic.TryGetValue(eventName, out list))
            {
                list = new EventPairList();
                dic.Add(eventName, list);
            }

            list.Add(pair);
            dic[eventName] = list;

            monitorExit(dic);
            return(true);
        }
Exemplo n.º 3
0
        protected static bool _deregisterEvent(EventPairDic dic, string eventName, object obj)
        {
            monitorEnter(dic);

            EventPairList list = null;

            if (!dic.TryGetValue(eventName, out list))
            {
                LogFile.Log("_deregisterEvent do not have event named\"" + eventName + "\"");
                return(false);
            }

            int count = list.Count;

            for (int i = 0; i < count; i++)
            {
                Pair pair = list[count - i - 1];
                if (pair.obj == obj)
                {
                    list.Remove(pair);
                    break;
                }
            }

            monitorExit(dic);

            return(true);
        }