共用方式為


Scheduler.ThreadPool 屬性

取得排程器,排程在 ThreadPool 上的工作。

Namespace:System.Reactive.Concurrency
裝配: System.Reactive.dll) 中的 System.Reactive (

語法

'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。 與產生運算子相關聯的處理會排程為使用 ThreadPool 排程器在 .NET 執行緒集區上執行。

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

另請參閱

參考

Scheduler 類別

System.Reactive.Concurrency 命名空間