|
Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
|
Übersetzung
Original
|
ThreadPool.QueueUserWorkItem-Methode (WaitCallback, Object)
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Parameter
- callBack
- Typ: System.Threading.WaitCallback
Ein WaitCallback, der die auszuführende Methode darstellt.
- state
- Typ: System.Object
Ein Objekt, das die von der Methode zu verwendenden Daten enthält.
Rückgabewert
Typ: System.Boolean| Ausnahme | Bedingung |
|---|---|
| NotSupportedException | |
| ArgumentNullException |
Hinweis |
|---|
Versionsinformationen
// This example shows how to create an object containing task // information, and pass that object to a task queued for // execution by the thread pool. using System; using System.Threading; // TaskInfo holds state information for a task that will be // executed by a ThreadPool thread. public class TaskInfo { // State information for the task. These members // can be implemented as read-only properties, read/write // properties with validation, and so on, as required. public string Boilerplate; public int Value; // Public constructor provides an easy way to supply all // the information needed for the task. public TaskInfo(string text, int number) { Boilerplate = text; Value = number; } } public class Example { public static void Main() { // Create an object containing the information needed // for the task. TaskInfo ti = new TaskInfo("This report displays the number {0}.", 42); // Queue the task and data. ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), ti); Console.WriteLine("Main thread does some work, then sleeps."); // If you comment out the Sleep, the main thread exits before // the ThreadPool task has a chance to run. ThreadPool 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."); } // The thread procedure performs the independent task, in this case // formatting and printing a very simple report. // static void ThreadProc(Object stateInfo) { TaskInfo ti = (TaskInfo) stateInfo; Console.WriteLine(ti.Boilerplate, ti.Value); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core-Rolle wird nicht unterstützt), Windows Server 2008 R2 (Server Core-Rolle wird mit SP1 oder höher unterstützt; Itanium wird nicht unterstützt)
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.
Hinweis