private void Listen()
        {
            if (_tokenSource != null && !_tokenSource.IsCancellationRequested)
            {
                _startAgain = true;
                InterruptListening();
                return;
            }

            _tokenSource = new CancellationTokenSource();
            var token = _tokenSource.Token;

            Task.Run(async() =>
            {
                while (!_tokenSource.IsCancellationRequested)
                {
                    var message = await _queueListener.StartListening();
                    if (message != null)
                    {
                        OnMessageDelivered(message);
                    }
                }
            }, token).ContinueWith(t =>
            {
                if (!_startAgain)
                {
                    return;
                }

                _startAgain = false;
                StartListening();
            }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
Exemplo n.º 2
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            _queueListener           = new QueueListener();
            _queueListener.Received += _queueListener_Received;
            _queueListener.StartListening("response");
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var host = new ServiceHost(typeof(StockService));

            host.Open();

            var queueListener = new QueueListener();

            queueListener.StartListening("request", true);

            Console.WriteLine("Press <Enter> to stop the services.");
            Console.ReadLine();

            queueListener.Dispose();
            host.Close();
        }
Exemplo n.º 4
0
 void StartListening()
 {
     _queueListener = new QueueListener();
     _queueListener.StartListening("request", true);
 }