public void ThrottledMarketDataStreamTasksMultithreadingStartStopTest()
        {
            var stream = new ThrottledMarketDataStream();

            var tasks = new List <Task>();

            for (int i = 0; i < 10; i++)
            {
                if (i % 2 == 0)
                {
                    tasks.Add(new Task(() => stream.Start()));
                }
                else
                {
                    tasks.Add(new Task(() => stream.End()));
                }
            }

            Parallel.ForEach(tasks, task =>
            {
                task.Start();
            });

            Task.WhenAll(tasks).ContinueWith(done =>
            {
                // this will not print untill all tasks have completed.
                System.Diagnostics.Debug.WriteLine("All tasks _stream Start/End  finished.");
                stream.End();
            });
        }
Exemplo n.º 2
0
        public void Run()
        {
            //// Arrange

            var aggregator = new ThrottledMarketDataStream();
            var streams    = new List <MarketDataStream>();
            var client     = new Client();

            for (var i = 0; i < 1000; i++)
            {
                var stream = new MarketDataStream();
                stream.AddWatcher(aggregator);
                streams.Add(stream);
            }

            aggregator.AddWatcher(client);

            //// Act
            aggregator.Start();

            foreach (var stream in streams)
            {
                stream.Start();
            }

            Thread.Sleep(10000);

            foreach (var stream in streams)
            {
                stream.End();
            }

            aggregator.End();

            //// Assert
        }