|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Classe ThreadPool
Spazio dei nomi: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Il tipo ThreadPool espone i seguenti membri.
| Nome | Descrizione | |
|---|---|---|
![]() ![]() | BindHandle(IntPtr) | Obsoleta. |
![]() ![]() | BindHandle(SafeHandle) | |
![]() ![]() | GetAvailableThreads | |
![]() ![]() ![]() | GetMaxThreads | |
![]() ![]() | GetMinThreads | |
![]() ![]() ![]() ![]() | QueueUserWorkItem(WaitCallback) | |
![]() ![]() ![]() ![]() | QueueUserWorkItem(WaitCallback, Object) | |
![]() ![]() | RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int32, Boolean) | |
![]() ![]() | RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int64, Boolean) | |
![]() ![]() | RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, TimeSpan, Boolean) | |
![]() ![]() | RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, UInt32, Boolean) | |
![]() ![]() ![]() | SetMaxThreads | |
![]() ![]() | SetMinThreads | |
![]() ![]() | UnsafeQueueNativeOverlapped | |
![]() ![]() | UnsafeQueueUserWorkItem | |
![]() ![]() | UnsafeRegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int32, Boolean) | |
![]() ![]() | UnsafeRegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int64, Boolean) | |
![]() ![]() | UnsafeRegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, TimeSpan, Boolean) | |
![]() ![]() | UnsafeRegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, UInt32, Boolean) |
Quando si crea un oggetto Task o Task<TResult> per eseguire in modo asincrono un'attività, per impostazione predefinita l'attività è pianificata per essere eseguita in un thread del pool di thread. Timer asincroni utilizzano il pool di thread. I thread del pool di thread eseguono i callback dalla classe System.Threading.Timer e generano eventi dalla classe System.Timers.Timer. Quando si utilizzano gli handle di attesa registrati, un thread di sistema monitora lo stato degli handle di attesa. Quando un'operazione di attesa viene completata, la funzione di callback corrispondente viene eseguita da un thread di lavoro contenuto nel pool di thread.
Nota |
|---|
Nota |
|---|
Nota |
|---|
Attenzione |
|---|
Nota |
|---|
L'attributo HostProtectionAttribute applicato a questo tipo di membro dispone del seguente valore per la proprietà Resources: Synchronization | ExternalThreading. L'oggetto HostProtectionAttribute non influisce sulle applicazioni desktop, che in genere vengono avviate facendo doppio clic sull'icona, digitando un comando oppure immettendo un URL in un browser. Per ulteriori informazioni, vedere la classe HostProtectionAttribute o programmazione per SQL Server e attributi di protezione host. |
| Topic | Location |
|---|---|
| Procedura: creare un gestore HTTP asincrono | Generazione di applicazioni Web ASP.NET |
| Procedura: creare un gestore HTTP asincrono | Compilazione di applicazioni Web ASP.NET in Visual Studio |
using System; using System.Threading; public class Example { public static void Main() { // Queue the task. ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc)); Console.WriteLine("Main thread does some work, then sleeps."); // If you comment out the Sleep, the main thread exits before // the thread pool task runs. The thread pool uses background // threads, which do not keep the application running. (This // is a simple example of a race condition.) Thread.Sleep(1000); Console.WriteLine("Main thread exits."); } // This thread procedure performs the task. static void ThreadProc(Object stateInfo) { // No state object was passed to QueueUserWorkItem, so // stateInfo is null. Console.WriteLine("Hello from the thread pool."); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.

