コード例 #1
0
 private static void ObserverStateCheck()
 {
     lock (ObserversAddRemoveQueue)
     {
         if (ObserversAddRemoveQueue.Count > 0)
         {
             try
             {
                 cacheLock.EnterWriteLock();
                 while (ObserversAddRemoveQueue.Count > 0)
                 {
                     Map3 <bool, EventID, EventObserver> set3   = ObserversAddRemoveQueue.Dequeue();
                     Map2 <EventID, EventObserver>       result = null;
                     foreach (Map2 <EventID, EventObserver> set2 in Observers)
                     {
                         if (set3.d2 == set2.d1 && set3.d3.Equals(set2.d2))
                         {
                             result = set2;
                             break;
                         }
                     }
                     if (set3.d1 == true)
                     {
                         if (result == null)
                         {
                             Observers.Add(new Map2 <EventID, EventObserver>(set3.d2, set3.d3));
                         }
                     }
                     else
                     {
                         if (result != null)
                         {
                             Observers.Remove(result);
                         }
                     }
                 }
             }
             finally
             {
                 cacheLock.ExitWriteLock();
             }
         }
     }
 }
コード例 #2
0
        private static void ThreadProcEvent()
        {
            m_eventThreadRunFlag = true;
            while (m_eventThreadRunFlag)
            {
                try
                {
                    lock (AsyncEventAddQueue)
                    {
                        if (AsyncEventAddQueue.Count == 0)
                        {
                            Monitor.Wait(AsyncEventAddQueue, 1000);
                        }
                        while (AsyncEventAddQueue.Count > 0)
                        {
                            AsyncEventReadyQueue.Enqueue(AsyncEventAddQueue.Dequeue());
                        }
                    }

                    if (ObserversAddRemoveQueue.Count > 0)
                    {
                        ObserverStateCheck();
                    }

                    while (AsyncEventReadyQueue.Count > 0)
                    {
                        Map2 <EventID, EventParam> args = AsyncEventReadyQueue.Dequeue();
                        Send(args.d1, args.d2);
                    }
                }
                catch (Exception ex)
                {
                    if (m_eventThreadRunFlag)
                    {
                        AsyncSend(EventID.etLog, new EventParam(null, 0, "Event Broker : Exception - " + ex.Message));
                    }
                }
            }
        }
コード例 #3
0
        private static void ThreadProcTimer()
        {
            m_timerThreadRunFlag = true;
            int minDurationTime = Int32.MaxValue;
            List <EventParamTimer> eventFinishs = new List <EventParamTimer>();

            while (m_timerThreadRunFlag)
            {
                try
                {
                    lock (AsyncTimerEventAddRemoveQueue)
                    {
                        if (AsyncTimerEventAddRemoveQueue.Count == 0 && minDurationTime > 0)
                        {
                            Monitor.Wait(AsyncTimerEventAddRemoveQueue, minDurationTime);
                        }

                        while (AsyncTimerEventAddRemoveQueue.Count > 0)
                        {
                            Map2 <bool, EventParamTimer> arg = AsyncTimerEventAddRemoveQueue.Dequeue();
                            if (arg.d1)
                            {// add
                                AsyncTimerEventReadyQueue.Add(arg.d2);
                            }
                            else
                            {// delete
                                foreach (EventParamTimer ept in AsyncTimerEventReadyQueue)
                                {
                                    if (ept.ID == arg.d2.ID && ept.Param.Equals(arg.d2.Param) == true)
                                    {
                                        AsyncTimerEventReadyQueue.Remove(ept);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    if (ObserversAddRemoveQueue.Count > 0)
                    {
                        ObserverStateCheck();
                    }

                    eventFinishs.Clear();
                    foreach (EventParamTimer ept in AsyncTimerEventReadyQueue)
                    {
                        if (ept.IsNeedRun() == true)
                        {
                            Send(ept.ID, ept.Param);
                            if (!ept.Repeat)
                            {
                                eventFinishs.Add(ept);
                            }
                            else
                            {
                                ept.SetNextTickCount();
                            }
                        }
                    }
                    foreach (EventParamTimer ept in eventFinishs)
                    {
                        AsyncTimerEventReadyQueue.Remove(ept);
                    }

                    minDurationTime = Int32.MaxValue;
                    foreach (EventParamTimer ept in AsyncTimerEventReadyQueue)
                    {
                        if (minDurationTime > ept.GetNextTickCount())
                        {
                            minDurationTime = ept.GetNextTickCount();
                        }
                    }
                }
                catch (ThreadInterruptedException /*ex*/) {}
                catch (Exception ex)
                {
                    if (m_timerThreadRunFlag)
                    {
                        AsyncSend(EventID.etLog, new EventParam(null, 0, "Event Broker : Exception - " + ex.Message));
                    }
                }
            }
        }