示例#1
0
        /// <summary>
        /// Start the device in the current thread. Should be used by implementations of the <see cref="DeviceRunner.Start"/> method.
        /// </summary>
        /// <remarks>
        /// Initializes the sockets prior to starting the device with <see cref="Initialize"/>.
        /// </remarks>
        protected internal void Run()
        {
            EnsureNotDisposed();

            Initialize();

            FrontendSocket.ReceiveReady += (sender, args) => FrontendHandler(args);
            BackendSocket.ReceiveReady  += (sender, args) => BackendHandler(args);

            DoneEvent.Reset();
            IsRunning = true;

            _poller.ClearSockets();
            _poller.AddSockets(new[] { FrontendSocket, BackendSocket });

            TimeSpan timeout = TimeSpan.FromMilliseconds(PollingIntervalMsec);

            try
            {
                while (IsRunning)
                {
                    _poller.Poll(timeout);
                }
            }
            catch (ZmqException)
            {
                // Swallow any exceptions thrown while stopping
                if (IsRunning)
                {
                    throw;
                }
            }

            IsRunning = false;
            DoneEvent.Set();
        }