ThreadPool.RegisterWaitForSingleObject メソッド

定義

WaitHandle を待機しているデリゲートを登録します。

オーバーロード

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, UInt32, Boolean)

32 ビット符号なし整数でミリ秒単位のタイムアウトを指定して、WaitHandle を待機するデリゲートを登録します。

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, TimeSpan, Boolean)

TimeSpan 値をタイムアウトとして指定して、WaitHandle を待機するデリゲートを登録します。

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int32, Boolean)

ミリ秒単位のタイムアウトとして 32 ビット符号付き整数を指定して、WaitHandle を待機するデリゲートを登録します。

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int64, Boolean)

64 ビット符号付き整数でミリ秒単位のタイムアウトを指定して、WaitHandle を待機するデリゲートを登録します。

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, UInt32, Boolean)

Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs

重要

この API は CLS 準拠ではありません。

32 ビット符号なし整数でミリ秒単位のタイムアウトを指定して、WaitHandle を待機するデリゲートを登録します。

public:
 static System::Threading::RegisteredWaitHandle ^ RegisterWaitForSingleObject(System::Threading::WaitHandle ^ waitObject, System::Threading::WaitOrTimerCallback ^ callBack, System::Object ^ state, System::UInt32 millisecondsTimeOutInterval, bool executeOnlyOnce);
[System.CLSCompliant(false)]
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, uint millisecondsTimeOutInterval, bool executeOnlyOnce);
[System.CLSCompliant(false)]
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval, bool executeOnlyOnce);
[System.CLSCompliant(false)]
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, uint millisecondsTimeOutInterval, bool executeOnlyOnce);
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * uint32 * bool -> System.Threading.RegisteredWaitHandle
[<System.CLSCompliant(false)>]
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * uint32 * bool -> System.Threading.RegisteredWaitHandle
Public Shared Function RegisterWaitForSingleObject (waitObject As WaitHandle, callBack As WaitOrTimerCallback, state As Object, millisecondsTimeOutInterval As UInteger, executeOnlyOnce As Boolean) As RegisteredWaitHandle

パラメーター

waitObject
WaitHandle

登録する WaitHandleMutex 以外の WaitHandle を使用します。

callBack
WaitOrTimerCallback

waitObject パラメーターがシグナル通知されたときに呼び出す WaitOrTimerCallback デリゲート。

state
Object

デリゲートに渡されたオブジェクト。

millisecondsTimeOutInterval
UInt32

ミリ秒単位のタイムアウト。 millisecondsTimeOutInterval パラメーターが 0 (ゼロ) の場合、関数はオブジェクトの状態をテストして、すぐに制御を戻します。 millisecondsTimeOutInterval が -1 の場合、関数はタイムアウトしません。

executeOnlyOnce
Boolean

デリゲートの呼び出し後、スレッドが waitObject パラメーターを待機しなくなる場合は true。待機が登録解除されるまでは、待機操作が完了するたびにタイマーをリセットする場合は false

戻り値

登録された待機操作をキャンセルするために使用できる RegisteredWaitHandle

属性

例外

millisecondsTimeOutInterval パラメーターが -1 未満。

次の例では、 メソッドを使用 RegisterWaitForSingleObject して、指定した待機ハンドルが通知されたときに、指定したコールバック メソッドを実行する方法を示します。 この例では、コールバック メソッドは で WaitProc、待機ハンドルは です AutoResetEvent

この例では、 TaskInfo 実行時にコールバックに渡される情報を保持するクラスを定義します。 この例では、 オブジェクトを TaskInfo 作成し、それに文字列データを割り当てます。 RegisteredWaitHandleメソッドによってRegisterWaitForSingleObject返される は、コールバック メソッドが にHandleアクセスできるように、 オブジェクトの TaskInfo フィールドにRegisteredWaitHandle割り当てられます。

コールバック メソッドに渡すオブジェクトとして をTaskInfo指定するだけでなく、 メソッドのRegisterWaitForSingleObject呼び出しでは、タスクが待機する を指定し、WaitOrTimerCallbackコールバック メソッドを表すWaitProcデリゲート、1 秒のタイムアウト間隔、および複数のコールバックを指定AutoResetEventします。

メイン スレッドがそのメソッドを呼び出Setして をAutoResetEvent通知すると、WaitOrTimerCallbackデリゲートが呼び出されます。 メソッドは WaitProcRegisteredWaitHandle タイムアウトが発生したかどうかを調べます。 待機ハンドルが通知されたためにコールバックが呼び出された場合、 WaitProc メソッドは を RegisteredWaitHandle登録解除し、追加のコールバックを停止します。 タイムアウトの場合、タスクは待機し続けます。 メソッドは WaitProc 、コンソールにメッセージを出力することによって終了します。

using namespace System;
using namespace System::Threading;

// TaskInfo contains data that will be passed to the callback
// method.
public ref class TaskInfo
{
public:
   TaskInfo()
   {
      Handle = nullptr;
      OtherInfo = "default";
   }

   RegisteredWaitHandle^ Handle;
   String^ OtherInfo;
};

ref class Example
{
public:

   // The callback method executes when the registered wait times out,
   // or when the WaitHandle (in this case AutoResetEvent) is signaled.
   // WaitProc unregisters the WaitHandle the first time the event is 
   // signaled.
   static void WaitProc( Object^ state, bool timedOut )
   {
      
      // The state Object must be cast to the correct type, because the
      // signature of the WaitOrTimerCallback delegate specifies type
      // Object.
      TaskInfo^ ti = static_cast<TaskInfo^>(state);
      String^ cause = "TIMED OUT";
      if (  !timedOut )
      {
         cause = "SIGNALED";
         
         // If the callback method executes because the WaitHandle is
         // signaled, stop future execution of the callback method
         // by unregistering the WaitHandle.
         if ( ti->Handle != nullptr )
                  ti->Handle->Unregister( nullptr );
      }

      Console::WriteLine( "WaitProc( {0}) executes on thread {1}; cause = {2}.", ti->OtherInfo, Thread::CurrentThread->GetHashCode(), cause );
   }

};

int main()
{
   
   // The main thread uses AutoResetEvent to signal the
   // registered wait handle, which executes the callback
   // method.
   AutoResetEvent^ ev = gcnew AutoResetEvent( false );
   TaskInfo^ ti = gcnew TaskInfo;
   ti->OtherInfo = "First task";
   
   // The TaskInfo for the task includes the registered wait
   // handle returned by RegisterWaitForSingleObject.  This
   // allows the wait to be terminated when the object has
   // been signaled once (see WaitProc).
   ti->Handle = ThreadPool::RegisterWaitForSingleObject( ev, gcnew WaitOrTimerCallback( Example::WaitProc ), ti, 1000, false );
   
   // The main thread waits three seconds, to demonstrate the
   // time-outs on the queued thread, and then signals.
   Thread::Sleep( 3100 );
   Console::WriteLine( "Main thread signals." );
   ev->Set();
   
   // The main thread sleeps, which should give the callback
   // method time to execute.  If you comment out this line, the
   // program usually ends before the ThreadPool thread can execute.
   Thread::Sleep( 1000 );
   
   // If you start a thread yourself, you can wait for it to end
   // by calling Thread::Join.  This option is not available with 
   // thread pool threads.
   return 0;
}
using System;
using System.Threading;

// TaskInfo contains data that will be passed to the callback
// method.
public class TaskInfo {
    public RegisteredWaitHandle Handle = null;
    public string OtherInfo = "default";
}

public class Example {
    public static void Main(string[] args) {
        // The main thread uses AutoResetEvent to signal the
        // registered wait handle, which executes the callback
        // method.
        AutoResetEvent ev = new AutoResetEvent(false);

        TaskInfo ti = new TaskInfo();
        ti.OtherInfo = "First task";
        // The TaskInfo for the task includes the registered wait
        // handle returned by RegisterWaitForSingleObject.  This
        // allows the wait to be terminated when the object has
        // been signaled once (see WaitProc).
        ti.Handle = ThreadPool.RegisterWaitForSingleObject(
            ev,
            new WaitOrTimerCallback(WaitProc),
            ti,
            1000,
            false
        );

        // The main thread waits three seconds, to demonstrate the
        // time-outs on the queued thread, and then signals.
        Thread.Sleep(3100);
        Console.WriteLine("Main thread signals.");
        ev.Set();

        // The main thread sleeps, which should give the callback
        // method time to execute.  If you comment out this line, the
        // program usually ends before the ThreadPool thread can execute.
        Thread.Sleep(1000);
        // If you start a thread yourself, you can wait for it to end
        // by calling Thread.Join.  This option is not available with 
        // thread pool threads.
    }
   
    // The callback method executes when the registered wait times out,
    // or when the WaitHandle (in this case AutoResetEvent) is signaled.
    // WaitProc unregisters the WaitHandle the first time the event is 
    // signaled.
    public static void WaitProc(object state, bool timedOut) {
        // The state object must be cast to the correct type, because the
        // signature of the WaitOrTimerCallback delegate specifies type
        // Object.
        TaskInfo ti = (TaskInfo) state;

        string cause = "TIMED OUT";
        if (!timedOut) {
            cause = "SIGNALED";
            // If the callback method executes because the WaitHandle is
            // signaled, stop future execution of the callback method
            // by unregistering the WaitHandle.
            if (ti.Handle != null)
                ti.Handle.Unregister(null);
        } 

        Console.WriteLine("WaitProc( {0} ) executes on thread {1}; cause = {2}.",
            ti.OtherInfo, 
            Thread.CurrentThread.GetHashCode().ToString(), 
            cause
        );
    }
}
Imports System.Threading

' TaskInfo contains data that will be passed to the callback
' method.
Public Class TaskInfo
    public Handle As RegisteredWaitHandle = Nothing
    public OtherInfo As String = "default"
End Class

Public Class Example

    <MTAThread> _
    Public Shared Sub Main()
        ' The main thread uses AutoResetEvent to signal the
        ' registered wait handle, which executes the callback
        ' method.
        Dim ev As New AutoResetEvent(false)

        Dim ti As New TaskInfo()
        ti.OtherInfo = "First task"
        ' The TaskInfo for the task includes the registered wait
        ' handle returned by RegisterWaitForSingleObject.  This
        ' allows the wait to be terminated when the object has
        ' been signaled once (see WaitProc).
        ti.Handle = ThreadPool.RegisterWaitForSingleObject( _
            ev, _
            New WaitOrTimerCallback(AddressOf WaitProc), _
            ti, _
            1000, _
            false _
        )

        ' The main thread waits about three seconds, to demonstrate 
        ' the time-outs on the queued task, and then signals.
        Thread.Sleep(3100)
        Console.WriteLine("Main thread signals.")
        ev.Set()

        ' The main thread sleeps, which should give the callback
        ' method time to execute.  If you comment out this line, the
        ' program usually ends before the ThreadPool thread can execute.
        Thread.Sleep(1000)
        ' If you start a thread yourself, you can wait for it to end
        ' by calling Thread.Join.  This option is not available with 
        ' thread pool threads.
    End Sub
   
    ' The callback method executes when the registered wait times out,
    ' or when the WaitHandle (in this case AutoResetEvent) is signaled.
    ' WaitProc unregisters the WaitHandle the first time the event is 
    ' signaled.
    Public Shared Sub WaitProc(state As Object, timedOut As Boolean)
        ' The state object must be cast to the correct type, because the
        ' signature of the WaitOrTimerCallback delegate specifies type
        ' Object.
        Dim ti As TaskInfo = CType(state, TaskInfo)

        Dim cause As String = "TIMED OUT"
        If Not timedOut Then
            cause = "SIGNALED"
            ' If the callback method executes because the WaitHandle is
            ' signaled, stop future execution of the callback method
            ' by unregistering the WaitHandle.
            If Not ti.Handle Is Nothing Then
                ti.Handle.Unregister(Nothing)
            End If
        End If 

        Console.WriteLine("WaitProc( {0} ) executes on thread {1}; cause = {2}.", _
            ti.OtherInfo, _
            Thread.CurrentThread.GetHashCode().ToString(), _
            cause _
        )
    End Sub
End Class

注釈

このメソッドによって返される を RegisteredWaitHandle 使用し終わったら、その RegisteredWaitHandle.Unregister メソッドを呼び出して待機ハンドルへの参照を解放します。 に を指定trueexecuteOnlyOnceしたRegisteredWaitHandle.Unregister場合でも、常に メソッドを呼び出することをお勧めします。 ガベージ コレクションは、登録されている待機ハンドルの RegisteredWaitHandle.Unregister ファイナライザーに応じてではなく、 メソッドを呼び出すと、より効率的に動作します。

メソッドは RegisterWaitForSingleObject 、指定したデリゲートをスレッド プールにキューに入れます。 ワーカー スレッドは、次のいずれかの場合にデリゲートを実行します。

  • 指定されたオブジェクトはシグナル状態です。
  • タイムアウト間隔が経過します。

メソッドは RegisterWaitForSingleObject 、指定したオブジェクトの の現在の WaitHandle状態を確認します。 オブジェクトの状態が符号なしの場合、 メソッドは待機操作を登録します。 待機操作は、スレッド プールのスレッドによって実行されます。 デリゲートは、オブジェクトの状態がシグナル状態になるか、タイムアウト間隔が経過したときにワーカー スレッドによって実行されます。 パラメーターが timeOutInterval 0 (ゼロ) ではなく、 executeOnlyOnce パラメーターが の場合、 falseイベントが通知されるかタイムアウト間隔が経過するたびにタイマーがリセットされます。

重要

Mutex基になる Windows API は既定WT_EXECUTEDEFAULTのフラグを使用するため、 for waitObject を使用してもコールバックの相互除外は提供されないため、各コールバックは個別のスレッド プール スレッドでディスパッチされます。 の代わりに、 Mutex最大カウントが 1 の を Semaphore 使用します。

待機操作を取り消すには、 メソッドを呼び出します RegisteredWaitHandle.Unregister

待機スレッドは Win32 WaitForMultipleObjects 関数を使用して、登録済みの待機操作を監視します。 したがって、 への複数の呼び出しで同じネイティブ オペレーティング システム ハンドルを使用する RegisterWaitForSingleObject必要がある場合は、Win32 DuplicateHandle 関数を使用してハンドルを複製する必要があります。 待機スレッドはリセットされる前にイベントが通知されることを検出しない可能性があるため、 に RegisterWaitForSingleObject渡されたイベント オブジェクトをパルスしないでください。

を返す前に、関数は一部の種類の同期オブジェクトの状態を変更します。 変更は、待機条件が満たされる原因となったシグナル状態のオブジェクトに対してのみ行われます。 たとえば、セマフォの数は 1 ずつ減らされます。

こちらもご覧ください

適用対象

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, TimeSpan, Boolean)

Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs

TimeSpan 値をタイムアウトとして指定して、WaitHandle を待機するデリゲートを登録します。

public:
 static System::Threading::RegisteredWaitHandle ^ RegisterWaitForSingleObject(System::Threading::WaitHandle ^ waitObject, System::Threading::WaitOrTimerCallback ^ callBack, System::Object ^ state, TimeSpan timeout, bool executeOnlyOnce);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, TimeSpan timeout, bool executeOnlyOnce);
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object state, TimeSpan timeout, bool executeOnlyOnce);
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, TimeSpan timeout, bool executeOnlyOnce);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * TimeSpan * bool -> System.Threading.RegisteredWaitHandle
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * TimeSpan * bool -> System.Threading.RegisteredWaitHandle
Public Shared Function RegisterWaitForSingleObject (waitObject As WaitHandle, callBack As WaitOrTimerCallback, state As Object, timeout As TimeSpan, executeOnlyOnce As Boolean) As RegisteredWaitHandle

パラメーター

waitObject
WaitHandle

登録する WaitHandleMutex 以外の WaitHandle を使用します。

callBack
WaitOrTimerCallback

waitObject パラメーターがシグナル通知されたときに呼び出す WaitOrTimerCallback デリゲート。

state
Object

デリゲートに渡されたオブジェクト。

timeout
TimeSpan

TimeSpan で表されるタイムアウト。 timeout が 0 (ゼロ) の場合、関数はオブジェクトの状態をテストして、すぐに制御を戻します。 timeout が -1 の場合、関数はタイムアウトしません。

executeOnlyOnce
Boolean

デリゲートの呼び出し後、スレッドが waitObject パラメーターを待機しなくなる場合は true。待機が登録解除されるまでは、待機操作が完了するたびにタイマーをリセットする場合は false

戻り値

ネイティブ ハンドルをカプセル化する RegisteredWaitHandle

属性

例外

timeout パラメーターが -1 未満。

パラメーターが timeoutInt32.MaxValue より大きい。

注釈

このメソッドによって返される を RegisteredWaitHandle 使用し終わったら、その RegisteredWaitHandle.Unregister メソッドを呼び出して待機ハンドルへの参照を解放します。 に を指定trueexecuteOnlyOnceしたRegisteredWaitHandle.Unregister場合でも、常に メソッドを呼び出することをお勧めします。 ガベージ コレクションは、登録されている待機ハンドルの RegisteredWaitHandle.Unregister ファイナライザーに応じてではなく、 メソッドを呼び出すと、より効率的に動作します。

メソッドは RegisterWaitForSingleObject 、指定したデリゲートをスレッド プールにキューに入れます。 ワーカー スレッドは、次のいずれかの場合にデリゲートを実行します。

  • 指定されたオブジェクトはシグナル状態です。
  • タイムアウト間隔が経過します。

メソッドは RegisterWaitForSingleObject 、指定したオブジェクトの の現在の WaitHandle状態を確認します。 オブジェクトの状態が符号なしの場合、 メソッドは待機操作を登録します。 待機操作は、スレッド プールのスレッドによって実行されます。 デリゲートは、オブジェクトの状態がシグナル状態になるか、タイムアウト間隔が経過したときにワーカー スレッドによって実行されます。 パラメーターが timeOutInterval 0 (ゼロ) ではなく、 executeOnlyOnce パラメーターが の場合、 falseイベントが通知されるかタイムアウト間隔が経過するたびにタイマーがリセットされます。

重要

Mutex基になる Windows API は既定WT_EXECUTEDEFAULTのフラグを使用するため、 for waitObject を使用してもコールバックの相互除外は提供されないため、各コールバックは個別のスレッド プール スレッドでディスパッチされます。 の代わりに、 Mutex最大カウントが 1 の を Semaphore 使用します。

待機操作を取り消すには、 メソッドを呼び出します RegisteredWaitHandle.Unregister

待機スレッドは Win32 WaitForMultipleObjects 関数を使用して、登録済みの待機操作を監視します。 したがって、 への複数の呼び出しで同じネイティブ オペレーティング システム ハンドルを使用する RegisterWaitForSingleObject必要がある場合は、Win32 DuplicateHandle 関数を使用してハンドルを複製する必要があります。 待機スレッドはリセットされる前にイベントが通知されることを検出しない可能性があるため、 に RegisterWaitForSingleObject渡されたイベント オブジェクトをパルスしないでください。

を返す前に、関数は一部の種類の同期オブジェクトの状態を変更します。 変更は、待機条件が満たされる原因となったシグナル状態のオブジェクトに対してのみ行われます。 たとえば、セマフォの数は 1 ずつ減らされます。

こちらもご覧ください

適用対象

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int32, Boolean)

Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs

ミリ秒単位のタイムアウトとして 32 ビット符号付き整数を指定して、WaitHandle を待機するデリゲートを登録します。

public:
 static System::Threading::RegisteredWaitHandle ^ RegisterWaitForSingleObject(System::Threading::WaitHandle ^ waitObject, System::Threading::WaitOrTimerCallback ^ callBack, System::Object ^ state, int millisecondsTimeOutInterval, bool executeOnlyOnce);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, int millisecondsTimeOutInterval, bool executeOnlyOnce);
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval, bool executeOnlyOnce);
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, int millisecondsTimeOutInterval, bool executeOnlyOnce);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * int * bool -> System.Threading.RegisteredWaitHandle
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * int * bool -> System.Threading.RegisteredWaitHandle
Public Shared Function RegisterWaitForSingleObject (waitObject As WaitHandle, callBack As WaitOrTimerCallback, state As Object, millisecondsTimeOutInterval As Integer, executeOnlyOnce As Boolean) As RegisteredWaitHandle

パラメーター

waitObject
WaitHandle

登録する WaitHandleMutex 以外の WaitHandle を使用します。

callBack
WaitOrTimerCallback

waitObject パラメーターがシグナル通知されたときに呼び出す WaitOrTimerCallback デリゲート。

state
Object

デリゲートに渡されるオブジェクト。

millisecondsTimeOutInterval
Int32

ミリ秒単位のタイムアウト。 millisecondsTimeOutInterval パラメーターが 0 (ゼロ) の場合、関数はオブジェクトの状態をテストして、すぐに制御を戻します。 millisecondsTimeOutInterval が -1 の場合、関数はタイムアウトしません。

executeOnlyOnce
Boolean

デリゲートの呼び出し後、スレッドが waitObject パラメーターを待機しなくなる場合は true。待機が登録解除されるまでは、待機操作が完了するたびにタイマーをリセットする場合は false

戻り値

ネイティブ ハンドルをカプセル化する RegisteredWaitHandle

属性

例外

millisecondsTimeOutInterval パラメーターが -1 未満。

注釈

このメソッドによって返される を RegisteredWaitHandle 使用し終わったら、その RegisteredWaitHandle.Unregister メソッドを呼び出して待機ハンドルへの参照を解放します。 に を指定trueexecuteOnlyOnceしたRegisteredWaitHandle.Unregister場合でも、常に メソッドを呼び出することをお勧めします。 ガベージ コレクションは、登録されている待機ハンドルの RegisteredWaitHandle.Unregister ファイナライザーに応じてではなく、 メソッドを呼び出すと、より効率的に動作します。

メソッドは RegisterWaitForSingleObject 、指定したデリゲートをスレッド プールにキューに入れます。 ワーカー スレッドは、次のいずれかの場合にデリゲートを実行します。

  • 指定されたオブジェクトはシグナル状態です。
  • タイムアウト間隔が経過します。

メソッドは RegisterWaitForSingleObject 、指定したオブジェクトの の現在の WaitHandle状態を確認します。 オブジェクトの状態が符号なしの場合、 メソッドは待機操作を登録します。 待機操作は、スレッド プールのスレッドによって実行されます。 デリゲートは、オブジェクトの状態がシグナル状態になるか、タイムアウト間隔が経過したときにワーカー スレッドによって実行されます。 パラメーターが timeOutInterval 0 (ゼロ) ではなく、 executeOnlyOnce パラメーターが の場合、 falseイベントが通知されるかタイムアウト間隔が経過するたびにタイマーがリセットされます。

重要

Mutex基になる Windows API は既定WT_EXECUTEDEFAULTのフラグを使用するため、 for waitObject を使用してもコールバックの相互除外は提供されないため、各コールバックは個別のスレッド プール スレッドでディスパッチされます。 の代わりに、 Mutex最大カウントが 1 の を Semaphore 使用します。

待機操作を取り消すには、 メソッドを呼び出します RegisteredWaitHandle.Unregister

待機スレッドは Win32 WaitForMultipleObjects 関数を使用して、登録済みの待機操作を監視します。 したがって、 への複数の呼び出しで同じネイティブ オペレーティング システム ハンドルを使用する RegisterWaitForSingleObject必要がある場合は、Win32 DuplicateHandle 関数を使用してハンドルを複製する必要があります。 待機スレッドはリセットされる前にイベントが通知されることを検出しない可能性があるため、 に RegisterWaitForSingleObject渡されたイベント オブジェクトをパルスしないでください。

を返す前に、関数は一部の種類の同期オブジェクトの状態を変更します。 変更は、待機条件が満たされる原因となったシグナル状態のオブジェクトに対してのみ行われます。 たとえば、セマフォの数は 1 ずつ減らされます。

こちらもご覧ください

適用対象

RegisterWaitForSingleObject(WaitHandle, WaitOrTimerCallback, Object, Int64, Boolean)

Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs
Source:
ThreadPoolWorkQueue.cs

64 ビット符号付き整数でミリ秒単位のタイムアウトを指定して、WaitHandle を待機するデリゲートを登録します。

public:
 static System::Threading::RegisteredWaitHandle ^ RegisterWaitForSingleObject(System::Threading::WaitHandle ^ waitObject, System::Threading::WaitOrTimerCallback ^ callBack, System::Object ^ state, long millisecondsTimeOutInterval, bool executeOnlyOnce);
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, long millisecondsTimeOutInterval, bool executeOnlyOnce);
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval, bool executeOnlyOnce);
public static System.Threading.RegisteredWaitHandle RegisterWaitForSingleObject (System.Threading.WaitHandle waitObject, System.Threading.WaitOrTimerCallback callBack, object? state, long millisecondsTimeOutInterval, bool executeOnlyOnce);
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * int64 * bool -> System.Threading.RegisteredWaitHandle
static member RegisterWaitForSingleObject : System.Threading.WaitHandle * System.Threading.WaitOrTimerCallback * obj * int64 * bool -> System.Threading.RegisteredWaitHandle
Public Shared Function RegisterWaitForSingleObject (waitObject As WaitHandle, callBack As WaitOrTimerCallback, state As Object, millisecondsTimeOutInterval As Long, executeOnlyOnce As Boolean) As RegisteredWaitHandle

パラメーター

waitObject
WaitHandle

登録する WaitHandleMutex 以外の WaitHandle を使用します。

callBack
WaitOrTimerCallback

waitObject パラメーターがシグナル通知されたときに呼び出す WaitOrTimerCallback デリゲート。

state
Object

デリゲートに渡されたオブジェクト。

millisecondsTimeOutInterval
Int64

ミリ秒単位のタイムアウト。 millisecondsTimeOutInterval パラメーターが 0 (ゼロ) の場合、関数はオブジェクトの状態をテストして、すぐに制御を戻します。 millisecondsTimeOutInterval が -1 の場合、関数はタイムアウトしません。

executeOnlyOnce
Boolean

デリゲートの呼び出し後、スレッドが waitObject パラメーターを待機しなくなる場合は true。待機が登録解除されるまでは、待機操作が完了するたびにタイマーをリセットする場合は false

戻り値

ネイティブ ハンドルをカプセル化する RegisteredWaitHandle

属性

例外

millisecondsTimeOutInterval パラメーターが -1 未満。

注釈

このメソッドによって返される を RegisteredWaitHandle 使用し終わったら、その RegisteredWaitHandle.Unregister メソッドを呼び出して待機ハンドルへの参照を解放します。 に を指定trueexecuteOnlyOnceしたRegisteredWaitHandle.Unregister場合でも、常に メソッドを呼び出することをお勧めします。 ガベージ コレクションは、登録されている待機ハンドルの RegisteredWaitHandle.Unregister ファイナライザーに応じてではなく、 メソッドを呼び出すと、より効率的に動作します。

メソッドは RegisterWaitForSingleObject 、指定したデリゲートをスレッド プールにキューに入れます。 ワーカー スレッドは、次のいずれかの場合にデリゲートを実行します。

  • 指定されたオブジェクトはシグナル状態です。
  • タイムアウト間隔が経過します。

メソッドは RegisterWaitForSingleObject 、指定したオブジェクトの の現在の WaitHandle状態を確認します。 オブジェクトの状態が符号なしの場合、 メソッドは待機操作を登録します。 待機操作は、スレッド プールのスレッドによって実行されます。 デリゲートは、オブジェクトの状態がシグナル状態になるか、タイムアウト間隔が経過したときにワーカー スレッドによって実行されます。 パラメーターが timeOutInterval 0 (ゼロ) ではなく、 executeOnlyOnce パラメーターが の場合、 falseイベントが通知されるかタイムアウト間隔が経過するたびにタイマーがリセットされます。

重要

Mutex基になる Windows API は既定WT_EXECUTEDEFAULTのフラグを使用するため、 for waitObject を使用してもコールバックの相互除外は提供されないため、各コールバックは個別のスレッド プール スレッドでディスパッチされます。 の代わりに、 Mutex最大カウントが 1 の を Semaphore 使用します。

待機操作を取り消すには、 メソッドを呼び出します RegisteredWaitHandle.Unregister

待機スレッドは Win32 WaitForMultipleObjects 関数を使用して、登録済みの待機操作を監視します。 したがって、 への複数の呼び出しで同じネイティブ オペレーティング システム ハンドルを使用する RegisterWaitForSingleObject必要がある場合は、Win32 DuplicateHandle 関数を使用してハンドルを複製する必要があります。 待機スレッドはリセットされる前にイベントが通知されることを検出しない可能性があるため、 に RegisterWaitForSingleObject渡されたイベント オブジェクトをパルスしないでください。

を返す前に、関数は一部の種類の同期オブジェクトの状態を変更します。 変更は、待機条件が満たされる原因となったシグナル状態のオブジェクトに対してのみ行われます。 たとえば、セマフォの数は 1 ずつ減らされます。

こちらもご覧ください

適用対象