}// Dispose()

        //
        //
        #endregion//Public Methods


        #region Private Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        //
        //
        //
        // *****************************************************
        // ****             ProcessNewPending()             ****
        // *****************************************************
        /// <summary>
        /// When new EventArgs are added to the InQueue, they are processed here
        /// and pushed onto internal pending Queue.
        /// </summary>
        private void ProcessNewPending()
        {
            IncomingEventArgs eventArgs;

            while (m_InQueue.TryDequeue(out eventArgs))                                     // remove from public queue
            {
                IncomingEventArgs e       = (IncomingEventArgs)eventArgs;
                DateTime          nextTry = DateTime.Now.AddSeconds(e.DelayInSeconds);
                // Elaborate counting used by EventWaitQueue.
                // TODO: Lets implement something simpler, like a counter for failed attempts inside event itself?
                // Add event to queue.
                while (m_Queue.ContainsKey(nextTry))
                {
                    nextTry = DateTime.Now.AddTicks(1L);            // smallest increment of counter.
                }
                m_Queue.Add(nextTry, e.EventArg);                   // pass in the original event.
                m_IncomingFactory.Recycle(e);                       // return to recycle bin.
            }
            m_QueueLength = m_InQueue.Count;                        // this is threadsafe I believe.
        } // ProcessNewPending()
        //
        //
        #endregion//Properties


        #region Public Methods
        // *****************************************************************
        // ****                     Public Methods                      ****
        // *****************************************************************
        //
        //
        // *****************************************
        // ***          AddPending()            ****
        // *****************************************
        /// <summary>
        /// Any thread can push onto this queue as an event to be resubmitted at later time.
        /// </summary>
        /// <param name="eventArg"></param>
        /// <param name="secsToWait"></param>
        public void AddPending(EventArgs eventArg, int secsToWait)
        {
            if (ResubmissionReady == null)
            {
                Exception ex = new Exception("EventWaitQueue: Cannot add to queue with no subscribers to ResubmissionReady event.");
                throw ex;
            }
            if (eventArg == null)
            {
                Exception ex = new Exception("EventWaitQueue: Cannot add a null EventArg to queue.");
                throw ex;
            }
            // Add to input queue
            IncomingEventArgs e = m_IncomingFactory.Get();

            e.EventArg       = eventArg;
            e.DelayInSeconds = secsToWait;
            m_InQueue.Enqueue(e);
            if (Log != null)
            {
                Log.NewEntry(LogLevel.Minor, "EventWaitQueue: Adding {0} to queue.", e);
            }
        } // Add()
Exemplo n.º 3
0
 private void ServerOnIncomingClient(IncomingEventArgs args)
 {
     // ReSharper disable once ObjectCreationAsStatement
     new Client(args.IncomingClient);
 }