Exemplo n.º 1
0
        internal static void Test(string[] args)
        {
            if (int.TryParse(args[0], out int res))
            {
                Item.loop = res;
            }
            var work_thread = Math.Min(8, Environment.ProcessorCount / 2);

            Console.WriteLine("WorkThread = " + work_thread.ToString());
            var loop      = Item.loop;
            var stopwatch = new Stopwatch();
            var item      = new Item(() =>
            {
                stopwatch.Stop();
                Console.WriteLine("over take " + stopwatch.ElapsedMilliseconds.ToString());
            });

            Console.WriteLine("Press Any Key Start");
            Console.ReadKey();

            var dispatch = new Dispatcher.DispatchCenter <Item>(DoWork, 1);

            stopwatch.Restart();
            for (var i = 0; i < loop; i++)
            {
                dispatch.Enqueue(item);
            }

            Console.ReadKey();
            item.Reset();

            var channels = new ThreadDispatcher <Item>(DoWork, 1, true);

            for (; ;)
            {
                stopwatch.Restart();
                for (var i = 0; i < loop; i++)
                {
                    channels.QueueWorkItemInternal(item);
                }
                item.Reset();
                Console.ReadKey();
            }
        }
Exemplo n.º 2
0
 public void Push(TaskCompletionSource <bool> tcs)
 {
     channels.QueueWorkItemInternal(tcs);
 }