Share via


ProcessModelSection.MaxWorkerThreads 屬性

定義

取得或設定值,表示 CLR 執行緒集區中每個 CPU 的背景工作執行緒最大數目。

public:
 property int MaxWorkerThreads { int get(); void set(int value); };
[System.Configuration.ConfigurationProperty("maxWorkerThreads", DefaultValue=20)]
[System.Configuration.IntegerValidator(MaxValue=2147483646, MinValue=1)]
public int MaxWorkerThreads { get; set; }
[<System.Configuration.ConfigurationProperty("maxWorkerThreads", DefaultValue=20)>]
[<System.Configuration.IntegerValidator(MaxValue=2147483646, MinValue=1)>]
member this.MaxWorkerThreads : int with get, set
Public Property MaxWorkerThreads As Integer

屬性值

執行緒的最大數目。 預設值為 20。

屬性

範例

下列程式碼範例示範如何存取 MaxWorkerThreads 屬性。


// Get the current MaxWorkerThreads property value.
int maxWorkerThreads = 
    processModelSection.MaxWorkerThreads;

// Set the MaxWorkerThreads property to 128.
processModelSection.MaxWorkerThreads = 128;
' Get the current MaxWorkerThreads property value.
   Dim maxWorkerThreads As Integer = _
   processModelSection.MaxWorkerThreads

' Set the MaxWorkerThreads property to 128.
processModelSection.MaxWorkerThreads = 128

備註

的值 MaxWorkerThreads 必須等於或大於 MinFreeThreads 組態區段中的 httpRuntime 設定。

您可以分別使用 MaxWorkerThreads 屬性和 屬性 MaxIOThreads 來設定背景工作執行緒和 I/O 執行緒數目,以控制 CPU 使用率。

這兩種執行緒類型之間的差異在於後者系結至 I/O 物件,例如資料流程或管道,而前者是傳統不受限制的執行緒。 針對 Internet Information Services (IIS) 6.0 版和更新版本,ASP.NET 處理背景工作執行緒的要求。 這是因為 ASP.NET 已整合在 IIS 中。

這些執行緒是從屬於應用程式的全進程 CLR 執行緒集區取得。

注意

允許執行緒的預設值通常足以保持 CPU 使用率高。 如果您的應用程式因為某些原因而變慢,或許正在等候外部資源,您可以嘗試將執行緒數目增加為小於 100 的值。

適用於

另請參閱