Пример #1
0
 public void EventReadyComplete()
 {
     if (UseThreadLock && LockHanlde != null)
     {
         LockHanlde.Set();
         LockHanlde = null;
     }
 }
Пример #2
0
        void CallEvent()
        {
            if (Ready == null)
            {
                return;
            }

            DEDEventArgs ev = null;

            lock (eventQueue)
            {
                ev = eventQueue.Peek();
            }

            int totalMsToWait = ev.Delay - (int)Math.Ceiling((DateTime.Now - ev.InsertedAt).TotalMilliseconds);

            if (totalMsToWait > 0)
            {
                System.Threading.Thread.Sleep(totalMsToWait);
            }

            lock (eventQueue)
            {
                // dqueue after the event completed.
                eventQueue.Dequeue();
            }

            if (UseThreadLock)
            {
                LockHanlde = new EventWaitHandle(false, EventResetMode.ManualReset);
            }

            try
            {
                Ready(this, ev);
            }
            catch (Exception ex)
            {
                // nothing here.
                LastError       = ex;
                LastErrorIndex += 1;
            }

            if (UseThreadLock)
            {
                try
                {
                    LockHanlde.WaitOne(ThreadLockTimeout);
                }
                catch (Exception ex)
                {
                    LastError       = ex;
                    LastErrorIndex += 1;
                }
            }
        }