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 的完美平方。 与 generate 运算符关联的处理计划为通过使用 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 命名空间