Поделиться через


Свойство Scheduler.ThreadPool

Возвращает планировщик, который планирует работу в ThreadPool.

Пространство имен:System.Reactive.Concurrency
Сборки: System.Reactive (в System.Reactive.dll)

Синтаксис

'Declaration
Public Shared ReadOnly Property ThreadPool As ThreadPoolScheduler
    Get
'Usage
Dim value As ThreadPoolScheduler

value = Scheduler.ThreadPool
public static ThreadPoolScheduler ThreadPool { get; }
public:
static property ThreadPoolScheduler^ ThreadPool {
    ThreadPoolScheduler^ get ();
}
static member ThreadPool : ThreadPoolScheduler
static function get ThreadPool () : ThreadPoolScheduler

Значение свойства

Тип: System.Reactive.Concurrency.ThreadPoolScheduler
Планировщик пула потоков.

Комментарии

Планировщик ThreadPool планирует выполнение действий в пуле потоков .NET. Этот планировщик идеально подходит для коротких операций.

Примеры

В этом примере кода оператор Generate используется для создания последовательности целых чисел, которые являются идеальными квадратами менее 1000. Обработка, связанная с оператором generate, запланирована для выполнения в пуле потоков .NET с помощью планировщика ThreadPool.

using System;
using System.Reactive.Linq;
using System.Reactive.Concurrency;

namespace Example
{
  class Program
  {
    static void Main()
    {
      //*********************************************************************************************//
      //*** Generate a sequence of integers which are the perfect squares that are less than 100  ***//
      //*********************************************************************************************//

      var obs = Observable.Generate(1,                      // Initial state value
                                    x => x * x < 1000,      // The termination condition. Terminate generation when false (the integer squared is not less than 1000)
                                    x => ++x,               // Iteration step function updates the state and returns the new state. In this case state is incremented by 1 
                                    x => x * x,             // Selector function determines the next resulting value in the sequence. The state of type in is squared.
                                    Scheduler.ThreadPool);  // The ThreadPool scheduler runs the generation on a thread pool thread instead of the main thread.

      using (IDisposable handle = obs.Subscribe(x => Console.WriteLine(x)))
      {
        Console.WriteLine("Press ENTER to exit...\n");
        Console.ReadLine();
      }
    }
  }
}

В следующих выходных данных показано выполнение примера кода.

Press ENTER to exit...

1
4
9
16
25
36
49
64
81
100
121
144
169
196
225
256
289
324
361
400
441
484
529
576
625
676
729
784
841
900
961

См. также:

Ссылка

Класс планировщика

Пространство имен System.Reactive.Concurrency