Example #1
0
        static void Main(string[] args)
        {
            try {
                Console.WriteLine("Begin");
                var queue = new TPLDataflowQueue();
                for (var i = 1; i <= 10; i++)
                {
                    queue.Enqueue(i.ToString());
                }

                var queueMultiThread = new TPLDataflowMultipleHandlers();
                var numbers          = Enumerable.Range(1, 10);
                foreach (var num in numbers)
                {
                    queueMultiThread.Enqueue(num.ToString());
                }

                var queueBroadcast = new TPLDataflowBroadcast();
                foreach (var num in Enumerable.Range(1, 10))
                {
                    // the broadcast alone will have only 1 message at a time which means that
                    // it has to wait that all the consumers will read it before fetching the next one
                    queueBroadcast.Enqueue(num.ToString());
                }

                // need this sleep because every job enqueued in the multi-threading queue is not necessarily finished
                // and the main when finished will not ensure that the other threads are finished
                Thread.Sleep(1000);

                Console.WriteLine("End");
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
            }
        }
Example #2
0
        public void StartTPLDataFlowMultipleHandlers()
        {
            var q       = new TPLDataflowMultipleHandlers();
            var numbers = Enumerable.Range(1, 10);

            foreach (var num in numbers)
            {
                q.Enqueue(num.ToString());
            }
        }