Exemple #1
0
 public void Stop()
 {
     if (_queue != null && _poller != null)
     {
         _queue.Stop();
         _poller.Stop();
     }
 }
Exemple #2
0
        private static void Main()
        {
            Console.Title = "NetMQ Multi-threaded Service";

            var queue = new QueueDevice("tcp://localhost:5555", "tcp://localhost:5556", DeviceMode.Threaded);

            var source = new CancellationTokenSource();

            s_token = source.Token;

            for (int threadId = 0; threadId < 10; threadId++)
            {
                Task.Factory.StartNew(WorkerRoutine, s_token);
            }

            queue.Start();

            var clientThreads = new List <Task>();

            for (int threadId = 0; threadId < 1000; threadId++)
            {
                int id = threadId;
                clientThreads.Add(Task.Factory.StartNew(() => ClientRoutine(id)));
            }

            Task.WaitAll(clientThreads.ToArray());

            source.Cancel();

            queue.Stop();

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }
Exemple #3
0
        private void CleanUpDevices()
        {
            if (QueueDevce != null)
            {
                if (QueueDevce.IsRunning)
                {
                    QueueDevce.Stop();
                    QueueDevce.Close();
                }

                QueueDevce.Dispose();
            }

            if (ForwarderDevice != null)
            {
                if (ForwarderDevice.IsRunning)
                {
                    ForwarderDevice.Stop();
                    ForwarderDevice.Close();
                }

                ForwarderDevice.Dispose();
            }

            if (this.MonitorChannel != null)
            {
                this.MonitorChannel.Dispose();
            }
            ////if (this.poller != null)
            ////{
            ////    this.poller.Dispose();
            ////}
        }
Exemple #4
0
        static void Main(string[] args)
        {
            using (var context = NetMQContext.Create())
            {
                //var queue = new QueueDevice(context, "tcp://localhost:5555", "inproc://workers", DeviceMode.Threaded);
                var queue = new QueueDevice(context, "tcp://localhost:5555", "tcp://localhost:5556", DeviceMode.Threaded);

                CancellationTokenSource source = new CancellationTokenSource();
                token = source.Token;

                List <Task> workerThreads = new List <Task>();
                for (int threadId = 0; threadId < 10; threadId++)
                {
                    NetMQContext ctx = context;
                    workerThreads.Add(Task.Factory.StartNew(() => WorkerRoutine(new Worker(Guid.NewGuid(), ctx)), token));
                }

                queue.Start();

                List <Task> clientThreads = new List <Task>();
                for (int threadId = 0; threadId < 1000; threadId++)
                {
                    int id = threadId;
                    clientThreads.Add(Task.Factory.StartNew(() => ClientRoutine(id)));
                }

                Task.WaitAll(clientThreads.ToArray());

                source.Cancel();

                queue.Stop();
            }

            Console.WriteLine("Press ENTER to exit...");
            Console.ReadLine();
        }