|
Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
|
Übersetzung
Original
|
WaitHandle-Klasse
System.MarshalByRefObject
System.Threading.WaitHandle
System.Threading.EventWaitHandle
System.Threading.Mutex
System.Threading.Semaphore
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Der WaitHandle-Typ macht die folgenden Member verfügbar.
| Name | Beschreibung | |
|---|---|---|
![]() ![]() | Handle | Veraltet. |
![]() | SafeWaitHandle |
| Name | Beschreibung | |
|---|---|---|
![]() ![]() | Close | |
![]() | CreateObjRef | |
![]() ![]() ![]() | Dispose() | |
![]() ![]() ![]() ![]() | Dispose(Boolean) | |
![]() ![]() ![]() ![]() | Equals(Object) | |
![]() ![]() ![]() ![]() | Finalize | |
![]() ![]() ![]() ![]() | GetHashCode | |
![]() | GetLifetimeService | |
![]() ![]() ![]() ![]() | GetType | |
![]() | InitializeLifetimeService | |
![]() ![]() ![]() ![]() | MemberwiseClone() | |
![]() | MemberwiseClone(Boolean) | |
![]() ![]() | SignalAndWait(WaitHandle, WaitHandle) | |
![]() ![]() | SignalAndWait(WaitHandle, WaitHandle, Int32, Boolean) | |
![]() ![]() | SignalAndWait(WaitHandle, WaitHandle, TimeSpan, Boolean) | |
![]() ![]() ![]() ![]() | ToString | |
![]() ![]() ![]() ![]() | WaitAll(WaitHandle[]) | |
![]() ![]() ![]() ![]() | WaitAll(WaitHandle[], Int32) | |
![]() ![]() ![]() ![]() | WaitAll(WaitHandle[], TimeSpan) | |
![]() ![]() | WaitAll(WaitHandle[], Int32, Boolean) | |
![]() ![]() | WaitAll(WaitHandle[], TimeSpan, Boolean) | |
![]() ![]() ![]() ![]() | WaitAny(WaitHandle[]) | |
![]() ![]() ![]() ![]() | WaitAny(WaitHandle[], Int32) | |
![]() ![]() ![]() ![]() | WaitAny(WaitHandle[], TimeSpan) | |
![]() ![]() | WaitAny(WaitHandle[], Int32, Boolean) | |
![]() ![]() | WaitAny(WaitHandle[], TimeSpan, Boolean) | |
![]() ![]() ![]() ![]() | WaitOne() | |
![]() ![]() ![]() | WaitOne(Int32) | |
![]() ![]() ![]() | WaitOne(TimeSpan) | |
![]() ![]() | WaitOne(Int32, Boolean) | |
![]() | WaitOne(TimeSpan, Boolean) |
| Name | Beschreibung | |
|---|---|---|
![]() ![]() ![]() ![]() ![]() | InvalidHandle | |
![]() ![]() ![]() ![]() | WaitTimeout |
| Name | Beschreibung | |
|---|---|---|
![]() ![]() ![]() | IDisposable.Dispose | Infrastruktur. |
using System; using System.Threading; public sealed class App { // Define an array with two AutoResetEvent WaitHandles. static WaitHandle[] waitHandles = new WaitHandle[] { new AutoResetEvent(false), new AutoResetEvent(false) }; // Define a random number generator for testing. static Random r = new Random(); static void Main() { // Queue up two tasks on two different threads; // wait until all tasks are completed. DateTime dt = DateTime.Now; Console.WriteLine("Main thread is waiting for BOTH tasks to complete."); ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[0]); ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[1]); WaitHandle.WaitAll(waitHandles); // The time shown below should match the longest task. Console.WriteLine("Both tasks are completed (time waited={0})", (DateTime.Now - dt).TotalMilliseconds); // Queue up two tasks on two different threads; // wait until any tasks are completed. dt = DateTime.Now; Console.WriteLine(); Console.WriteLine("The main thread is waiting for either task to complete."); ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[0]); ThreadPool.QueueUserWorkItem(new WaitCallback(DoTask), waitHandles[1]); int index = WaitHandle.WaitAny(waitHandles); // The time shown below should match the shortest task. Console.WriteLine("Task {0} finished first (time waited={1}).", index + 1, (DateTime.Now - dt).TotalMilliseconds); } static void DoTask(Object state) { AutoResetEvent are = (AutoResetEvent) state; int time = 1000 * r.Next(2, 10); Console.WriteLine("Performing a task for {0} milliseconds.", time); Thread.Sleep(time); are.Set(); } } // This code produces output similar to the following: // // Main thread is waiting for BOTH tasks to complete. // Performing a task for 7000 milliseconds. // Performing a task for 4000 milliseconds. // Both tasks are completed (time waited=7064.8052) // // The main thread is waiting for either task to complete. // Performing a task for 2000 milliseconds. // Performing a task for 2000 milliseconds. // Task 1 finished first (time waited=2000.6528).
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.


