예제 #1
0
        private static void runTaskOnCurrentThreadScheduler()
        {
            const int MAX_TASKS = 100;

            Console.WriteLine("Main thread id: {0}", Thread.CurrentThread.ManagedThreadId);

            var fallBackScheduler = new FallbackScheduler();
            var scheduler         = new CurrentThreadScheduler(new FallbackScheduler());
            var taskfactory       = new TaskFactory(scheduler);
            var tasks             = Enumerable.Range(0, MAX_TASKS).Select(taskId => taskfactory.StartNew(() =>
            {
                Console.WriteLine(" Task: {0} tid: {1}", taskId,
                                  Thread.CurrentThread.ManagedThreadId);
            }));

            Task.WhenAll(tasks).Wait();
        }
 public CurrentThreadScheduler(FallbackScheduler alternateScheduler)
 {
     m_alternateScheduler = alternateScheduler;
 }