Provides a task scheduler that ensures a maximum concurrency level while running on top of the ThreadPool. This is a sample from MSDN - http://msdn.microsoft.com/ru-ru/library/ee789351.aspx
Inheritance: TaskScheduler
Example #1
0
        static void Main()
        {
            LimitedConcurrencyLevelTaskScheduler lcts = new LimitedConcurrencyLevelTaskScheduler(1);
            TaskFactory factory = new TaskFactory(lcts);

            factory.StartNew(() =>
            {
                for (int i = 0; i < 500; i++)
                {
                    Console.Write("{0} on thread {1}", i, Thread.CurrentThread.ManagedThreadId);
                }
            }
                             );

            Console.ReadKey();
        }
Example #2
0
 static AsyncFunctions()
 {
     // This initialization could be lazy (and of course be any other TaskScheduler)
     var fourThreadScheduler = new LimitedConcurrencyLevelTaskScheduler(4);
     _fourThreadFactory = new TaskFactory(fourThreadScheduler);
 }