NetMQ.Poller.RemoveTimer C# (CSharp) Method

RemoveTimer() public method

Delete the given timer from this Poller's list.
timer must not be null. This poller must not have already been disposed.
public RemoveTimer ( [ timer ) : void
timer [ the NetMQTimer to remove from the list
return void
        public void RemoveTimer([NotNull] NetMQTimer timer)
        {
            if (timer == null)
            {
                throw new ArgumentNullException("timer");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException("Poller is disposed");
            }

            timer.When = -1;
            m_zombies.Add(timer);
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        ///     run the broker - if not bound to endpoint automatically binds to known endpoint
        /// </summary>
        /// <param name="token">CancellationToken to cancel the method</param>
        /// <exception cref="InvalidOperationException">Can't start same broker more than once!</exception>
        public void RunSynchronous(CancellationToken token)
        {
            if (m_isRunning)
            {
                throw new InvalidOperationException("Can't start same broker more than once!");
            }

            if (!m_isBound)
            {
                Bind();
            }

            m_isRunning = true;

            using (var poller = new NetMQ.Poller())
            {
                Socket.ReceiveReady += ProcessReceiveMessage;
                // get timer for scheduling heartbeat
                var timer = new NetMQTimer(HeartbeatInterval);
                // send every 'HeartbeatInterval' a heartbeat to all not expired workers
                timer.Elapsed += (s, e) => SendHeartbeat();

                poller.AddSocket(Socket);
                poller.AddTimer(timer);

                Log("[BROKER] Starting to listen for incoming messages ...");

                // start the poller and wait for the return, which will happen once token is
                // signalling Cancel(!)
                Task.Factory.StartNew(poller.Start, token).Wait();

                Log("[BROKER] ... Stopped!");

                // clean up
                poller.RemoveTimer(timer);
                poller.RemoveSocket(Socket);
                // unregister event handler
                Socket.ReceiveReady -= ProcessReceiveMessage;
            }

            m_isRunning = false;
        }
All Usage Examples Of NetMQ.Poller::RemoveTimer