WaitHandle.SignalAndWait Méthode

Définition

Signale un WaitHandle et attend un autre.Signals one WaitHandle and waits on another.

Surcharges

SignalAndWait(WaitHandle, WaitHandle)

Signale un WaitHandle et attend un autre.Signals one WaitHandle and waits on another.

SignalAndWait(WaitHandle, WaitHandle, Int32, Boolean)

Signale un WaitHandle et en attend un autre, en spécifiant un délai sous la forme d'un entier signé 32 bits et en spécifiant s'il faut quitter le domaine de synchronisation du contexte avant de commencer l'attente.Signals one WaitHandle and waits on another, specifying a time-out interval as a 32-bit signed integer and specifying whether to exit the synchronization domain for the context before entering the wait.

SignalAndWait(WaitHandle, WaitHandle, TimeSpan, Boolean)

Signale un WaitHandle et en attend un autre, en spécifiant le délai sous la forme d’une valeur TimeSpan et en spécifiant s’il faut quitter le domaine de synchronisation du contexte avant de commencer l’attente.Signals one WaitHandle and waits on another, specifying the time-out interval as a TimeSpan and specifying whether to exit the synchronization domain for the context before entering the wait.

SignalAndWait(WaitHandle, WaitHandle)

Signale un WaitHandle et attend un autre.Signals one WaitHandle and waits on another.

public:
 static bool SignalAndWait(System::Threading::WaitHandle ^ toSignal, System::Threading::WaitHandle ^ toWaitOn);
public static bool SignalAndWait (System.Threading.WaitHandle toSignal, System.Threading.WaitHandle toWaitOn);
static member SignalAndWait : System.Threading.WaitHandle * System.Threading.WaitHandle -> bool
Public Shared Function SignalAndWait (toSignal As WaitHandle, toWaitOn As WaitHandle) As Boolean

Paramètres

toSignal
WaitHandle

WaitHandle à signaler.The WaitHandle to signal.

toWaitOn
WaitHandle

WaitHandle à attendre.The WaitHandle to wait on.

Retours

Boolean

true si le signal et l'attente se terminent avec succès ; si l'attente ne se termine pas, la méthode ne retourne pas.true if both the signal and the wait complete successfully; if the wait does not complete, the method does not return.

Exceptions

toSignal a la valeur null.toSignal is null.

- ou --or- toWaitOn a la valeur null.toWaitOn is null.

La méthode a été appelée sur un thread à l’état STA.The method was called on a thread in STA state.

toSignal est un sémaphore, et possède déjà un nombre complet.toSignal is a semaphore, and it already has a full count.

L’attente s’est arrêtée, car un thread s’est terminé sans libérer de mutex.The wait completed because a thread exited without releasing a mutex. Cette exception n’est pas levée sur Windows 98 ou Windows Millennium Edition.This exception is not thrown on Windows 98 or Windows Millennium Edition.

Exemples

L’exemple de code suivant utilise la SignalAndWait(WaitHandle, WaitHandle) surcharge de méthode pour permettre au thread principal de signaler un thread bloqué, puis d’attendre que le thread termine une tâche.The following code example uses the SignalAndWait(WaitHandle, WaitHandle) method overload to allow the main thread to signal a blocked thread and then wait until the thread finishes a task.

L’exemple démarre cinq threads, les autorise à se bloquer sur un EventWaitHandle créé avec l' EventResetMode.AutoReset indicateur, puis libère un thread chaque fois que l’utilisateur appuie sur la touche entrée.The example starts five threads, allows them to block on an EventWaitHandle created with the EventResetMode.AutoReset flag, and then releases one thread each time the user presses the ENTER key. L’exemple met ensuite en file d’attente les cinq autres threads et les libère tous à l’aide d’un EventWaitHandle créé avec l' EventResetMode.ManualReset indicateur.The example then queues another five threads and releases them all using an EventWaitHandle created with the EventResetMode.ManualReset flag.

using namespace System;
using namespace System::Threading;

public ref class Example
{
private:
   // The EventWaitHandle used to demonstrate the difference
   // between AutoReset and ManualReset synchronization events.
   //
   static EventWaitHandle^ ewh;

   // A counter to make sure all threads are started and
   // blocked before any are released. A Long is used to show
   // the use of the 64-bit Interlocked methods.
   //
   static __int64 threadCount = 0;

   // An AutoReset event that allows the main thread to block
   // until an exiting thread has decremented the count.
   //
   static EventWaitHandle^ clearCount =
      gcnew EventWaitHandle( false,EventResetMode::AutoReset );

public:
   [MTAThread]
   static void main()
   {
      // Create an AutoReset EventWaitHandle.
      //
      ewh = gcnew EventWaitHandle( false,EventResetMode::AutoReset );
      
      // Create and start five numbered threads. Use the
      // ParameterizedThreadStart delegate, so the thread
      // number can be passed as an argument to the Start
      // method.
      for ( int i = 0; i <= 4; i++ )
      {
         Thread^ t = gcnew Thread(
            gcnew ParameterizedThreadStart( ThreadProc ) );
         t->Start( i );
      }
      
      // Wait until all the threads have started and blocked.
      // When multiple threads use a 64-bit value on a 32-bit
      // system, you must access the value through the
      // Interlocked class to guarantee thread safety.
      //
      while ( Interlocked::Read( threadCount ) < 5 )
      {
         Thread::Sleep( 500 );
      }

      // Release one thread each time the user presses ENTER,
      // until all threads have been released.
      //
      while ( Interlocked::Read( threadCount ) > 0 )
      {
         Console::WriteLine( L"Press ENTER to release a waiting thread." );
         Console::ReadLine();
         
         // SignalAndWait signals the EventWaitHandle, which
         // releases exactly one thread before resetting,
         // because it was created with AutoReset mode.
         // SignalAndWait then blocks on clearCount, to
         // allow the signaled thread to decrement the count
         // before looping again.
         //
         WaitHandle::SignalAndWait( ewh, clearCount );
      }
      Console::WriteLine();
      
      // Create a ManualReset EventWaitHandle.
      //
      ewh = gcnew EventWaitHandle( false,EventResetMode::ManualReset );
      
      // Create and start five more numbered threads.
      //
      for ( int i = 0; i <= 4; i++ )
      {
         Thread^ t = gcnew Thread(
            gcnew ParameterizedThreadStart( ThreadProc ) );
         t->Start( i );
      }
      
      // Wait until all the threads have started and blocked.
      //
      while ( Interlocked::Read( threadCount ) < 5 )
      {
         Thread::Sleep( 500 );
      }

      // Because the EventWaitHandle was created with
      // ManualReset mode, signaling it releases all the
      // waiting threads.
      //
      Console::WriteLine( L"Press ENTER to release the waiting threads." );
      Console::ReadLine();
      ewh->Set();

   }

   static void ThreadProc( Object^ data )
   {
      int index = static_cast<Int32>(data);

      Console::WriteLine( L"Thread {0} blocks.", data );
      // Increment the count of blocked threads.
      Interlocked::Increment( threadCount );
      
      // Wait on the EventWaitHandle.
      ewh->WaitOne();

      Console::WriteLine( L"Thread {0} exits.", data );
      // Decrement the count of blocked threads.
      Interlocked::Decrement( threadCount );
      
      // After signaling ewh, the main thread blocks on
      // clearCount until the signaled thread has
      // decremented the count. Signal it now.
      //
      clearCount->Set();
   }
};
using System;
using System.Threading;

public class Example
{
    // The EventWaitHandle used to demonstrate the difference
    // between AutoReset and ManualReset synchronization events.
    //
    private static EventWaitHandle ewh;

    // A counter to make sure all threads are started and
    // blocked before any are released. A Long is used to show
    // the use of the 64-bit Interlocked methods.
    //
    private static long threadCount = 0;

    // An AutoReset event that allows the main thread to block
    // until an exiting thread has decremented the count.
    //
    private static EventWaitHandle clearCount = 
        new EventWaitHandle(false, EventResetMode.AutoReset);

    [MTAThread]
    public static void Main()
    {
        // Create an AutoReset EventWaitHandle.
        //
        ewh = new EventWaitHandle(false, EventResetMode.AutoReset);

        // Create and start five numbered threads. Use the
        // ParameterizedThreadStart delegate, so the thread
        // number can be passed as an argument to the Start 
        // method.
        for (int i = 0; i <= 4; i++)
        {
            Thread t = new Thread(
                new ParameterizedThreadStart(ThreadProc)
            );
            t.Start(i);
        }

        // Wait until all the threads have started and blocked.
        // When multiple threads use a 64-bit value on a 32-bit
        // system, you must access the value through the
        // Interlocked class to guarantee thread safety.
        //
        while (Interlocked.Read(ref threadCount) < 5)
        {
            Thread.Sleep(500);
        }

        // Release one thread each time the user presses ENTER,
        // until all threads have been released.
        //
        while (Interlocked.Read(ref threadCount) > 0)
        {
            Console.WriteLine("Press ENTER to release a waiting thread.");
            Console.ReadLine();

            // SignalAndWait signals the EventWaitHandle, which
            // releases exactly one thread before resetting, 
            // because it was created with AutoReset mode. 
            // SignalAndWait then blocks on clearCount, to 
            // allow the signaled thread to decrement the count
            // before looping again.
            //
            WaitHandle.SignalAndWait(ewh, clearCount);
        }
        Console.WriteLine();

        // Create a ManualReset EventWaitHandle.
        //
        ewh = new EventWaitHandle(false, EventResetMode.ManualReset);

        // Create and start five more numbered threads.
        //
        for(int i=0; i<=4; i++)
        {
            Thread t = new Thread(
                new ParameterizedThreadStart(ThreadProc)
            );
            t.Start(i);
        }

        // Wait until all the threads have started and blocked.
        //
        while (Interlocked.Read(ref threadCount) < 5)
        {
            Thread.Sleep(500);
        }

        // Because the EventWaitHandle was created with
        // ManualReset mode, signaling it releases all the
        // waiting threads.
        //
        Console.WriteLine("Press ENTER to release the waiting threads.");
        Console.ReadLine();
        ewh.Set();
    }

    public static void ThreadProc(object data)
    {
        int index = (int) data;

        Console.WriteLine("Thread {0} blocks.", data);
        // Increment the count of blocked threads.
        Interlocked.Increment(ref threadCount);

        // Wait on the EventWaitHandle.
        ewh.WaitOne();

        Console.WriteLine("Thread {0} exits.", data);
        // Decrement the count of blocked threads.
        Interlocked.Decrement(ref threadCount);

        // After signaling ewh, the main thread blocks on
        // clearCount until the signaled thread has 
        // decremented the count. Signal it now.
        //
        clearCount.Set();
    }
}
Imports System.Threading

Public Class Example

    ' The EventWaitHandle used to demonstrate the difference
    ' between AutoReset and ManualReset synchronization events.
    '
    Private Shared ewh As EventWaitHandle

    ' A counter to make sure all threads are started and
    ' blocked before any are released. A Long is used to show
    ' the use of the 64-bit Interlocked methods.
    '
    Private Shared threadCount As Long = 0

    ' An AutoReset event that allows the main thread to block
    ' until an exiting thread has decremented the count.
    '
    Private Shared clearCount As New EventWaitHandle(False, _
        EventResetMode.AutoReset)

    <MTAThread> _
    Public Shared Sub Main()

        ' Create an AutoReset EventWaitHandle.
        '
        ewh = New EventWaitHandle(False, EventResetMode.AutoReset)

        ' Create and start five numbered threads. Use the
        ' ParameterizedThreadStart delegate, so the thread
        ' number can be passed as an argument to the Start 
        ' method.
        For i As Integer = 0 To 4
            Dim t As New Thread(AddressOf ThreadProc)
            t.Start(i)
        Next i

        ' Wait until all the threads have started and blocked.
        ' When multiple threads use a 64-bit value on a 32-bit
        ' system, you must access the value through the
        ' Interlocked class to guarantee thread safety.
        '
        While Interlocked.Read(threadCount) < 5
            Thread.Sleep(500)
        End While

        ' Release one thread each time the user presses ENTER,
        ' until all threads have been released.
        '
        While Interlocked.Read(threadCount) > 0
            Console.WriteLine("Press ENTER to release a waiting thread.")
            Console.ReadLine()

            ' SignalAndWait signals the EventWaitHandle, which
            ' releases exactly one thread before resetting, 
            ' because it was created with AutoReset mode. 
            ' SignalAndWait then blocks on clearCount, to 
            ' allow the signaled thread to decrement the count
            ' before looping again.
            '
            WaitHandle.SignalAndWait(ewh, clearCount)
        End While
        Console.WriteLine()

        ' Create a ManualReset EventWaitHandle.
        '
        ewh = New EventWaitHandle(False, EventResetMode.ManualReset)

        ' Create and start five more numbered threads.
        '
        For i As Integer = 0 To 4
            Dim t As New Thread(AddressOf ThreadProc)
            t.Start(i)
        Next i

        ' Wait until all the threads have started and blocked.
        '
        While Interlocked.Read(threadCount) < 5
            Thread.Sleep(500)
        End While

        ' Because the EventWaitHandle was created with
        ' ManualReset mode, signaling it releases all the
        ' waiting threads.
        '
        Console.WriteLine("Press ENTER to release the waiting threads.")
        Console.ReadLine()
        ewh.Set()
        
    End Sub

    Public Shared Sub ThreadProc(ByVal data As Object)
        Dim index As Integer = CInt(data)

        Console.WriteLine("Thread {0} blocks.", data)
        ' Increment the count of blocked threads.
        Interlocked.Increment(threadCount)

        ' Wait on the EventWaitHandle.
        ewh.WaitOne()

        Console.WriteLine("Thread {0} exits.", data)
        ' Decrement the count of blocked threads.
        Interlocked.Decrement(threadCount)

        ' After signaling ewh, the main thread blocks on
        ' clearCount until the signaled thread has 
        ' decremented the count. Signal it now.
        '
        clearCount.Set()
    End Sub
End Class

Remarques

Il n’est pas garanti que cette opération soit atomique.This operation is not guaranteed to be atomic. Une fois que le thread actuel signale toSignal mais avant qu’il n’attende toWaitOn , un thread qui s’exécute sur un autre processeur peut le signaler toWaitOn ou l’attendre.After the current thread signals toSignal but before it waits on toWaitOn, a thread that is running on another processor might signal toWaitOn or wait on it.

S’applique à

SignalAndWait(WaitHandle, WaitHandle, Int32, Boolean)

Signale un WaitHandle et en attend un autre, en spécifiant un délai sous la forme d'un entier signé 32 bits et en spécifiant s'il faut quitter le domaine de synchronisation du contexte avant de commencer l'attente.Signals one WaitHandle and waits on another, specifying a time-out interval as a 32-bit signed integer and specifying whether to exit the synchronization domain for the context before entering the wait.

public:
 static bool SignalAndWait(System::Threading::WaitHandle ^ toSignal, System::Threading::WaitHandle ^ toWaitOn, int millisecondsTimeout, bool exitContext);
public static bool SignalAndWait (System.Threading.WaitHandle toSignal, System.Threading.WaitHandle toWaitOn, int millisecondsTimeout, bool exitContext);
static member SignalAndWait : System.Threading.WaitHandle * System.Threading.WaitHandle * int * bool -> bool
Public Shared Function SignalAndWait (toSignal As WaitHandle, toWaitOn As WaitHandle, millisecondsTimeout As Integer, exitContext As Boolean) As Boolean

Paramètres

toSignal
WaitHandle

WaitHandle à signaler.The WaitHandle to signal.

toWaitOn
WaitHandle

WaitHandle à attendre.The WaitHandle to wait on.

millisecondsTimeout
Int32

Entier qui représente l'intervalle à attendre.An integer that represents the interval to wait. Si la valeur est Infinite, c'est-à-dire -1, l'attente est infinie.If the value is Infinite, that is, -1, the wait is infinite.

exitContext
Boolean

true pour quitter le domaine de synchronisation du contexte avant l'attente (dans le cas d'un contexte synchronisé) et l'acquérir à nouveau ensuite ; sinon, false.true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false.

Retours

Boolean

true si le signal et l'attente se sont terminés avec succès ou false si le signal s'est terminé mais que l'attente a expiré.true if both the signal and the wait completed successfully, or false if the signal completed but the wait timed out.

Exceptions

toSignal a la valeur null.toSignal is null.

- ou --or- toWaitOn a la valeur null.toWaitOn is null.

La méthode est appelée sur un thread à l’état STA.The method is called on a thread in STA state.

WaitHandle ne peut pas être signalé, car il dépasse sa valeur maximale.The WaitHandle cannot be signaled because it would exceed its maximum count.

millisecondsTimeout est un nombre négatif différent de -1, qui représente un délai d’attente infini.millisecondsTimeout is a negative number other than -1, which represents an infinite time-out.

L’attente s’est arrêtée, car un thread s’est terminé sans libérer de mutex.The wait completed because a thread exited without releasing a mutex. Cette exception n’est pas levée sur Windows 98 ou Windows Millennium Edition.This exception is not thrown on Windows 98 or Windows Millennium Edition.

Remarques

Il n’est pas garanti que cette opération soit atomique.This operation is not guaranteed to be atomic. Une fois que le thread actuel signale toSignal mais avant qu’il n’attende toWaitOn , un thread qui s’exécute sur un autre processeur peut le signaler toWaitOn ou l’attendre.After the current thread signals toSignal but before it waits on toWaitOn, a thread that is running on another processor might signal toWaitOn or wait on it.

Si millisecondsTimeout est égal à zéro, la méthode n’est pas bloquée.If millisecondsTimeout is zero, the method does not block. Il teste l’état de toWaitOn et retourne immédiatement.It tests the state of the toWaitOn and returns immediately.

Remarques sur la sortie du contexteNotes on Exiting the Context

Le exitContext paramètre n’a aucun effet, à moins que la SignalAndWait méthode ne soit appelée à partir d’un contexte managé non défini par défaut.The exitContext parameter has no effect unless the SignalAndWait method is called from inside a nondefault managed context. Cela peut se produire si votre thread est à l’intérieur d’un appel à une instance d’une classe dérivée de ContextBoundObject .This can happen if your thread is inside a call to an instance of a class derived from ContextBoundObject. Même si vous exécutez actuellement une méthode sur une classe qui ne dérive pas de ContextBoundObject , comme String , vous pouvez être dans un contexte non défini par défaut si un ContextBoundObject est sur votre pile dans le domaine d’application actuel.Even if you are currently executing a method on a class that does not derive from ContextBoundObject, like String, you can be in a nondefault context if a ContextBoundObject is on your stack in the current application domain.

Lorsque votre code s’exécute dans un contexte non défini par défaut, true la spécification de pour exitContext oblige le thread à quitter le contexte managé non défini par défaut (c’est-à-dire à passer au contexte par défaut) avant d’exécuter la SignalAndWait méthode.When your code is executing in a nondefault context, specifying true for exitContext causes the thread to exit the nondefault managed context (that is, to transition to the default context) before executing the SignalAndWait method. Le thread retourne au contexte par défaut d’origine une fois l’appel à la SignalAndWait méthode terminé.The thread returns to the original nondefault context after the call to the SignalAndWait method completes.

Cela peut être utile lorsque la classe liée au contexte a SynchronizationAttribute .This can be useful when the context-bound class has SynchronizationAttribute. Dans ce cas, tous les appels aux membres de la classe sont automatiquement synchronisés et le domaine de synchronisation est le corps entier du code pour la classe.In that case, all calls to members of the class are automatically synchronized, and the synchronization domain is the entire body of code for the class. Si le code de la pile des appels d’un membre appelle la SignalAndWait méthode et spécifie true pour exitContext , le thread quitte le domaine de synchronisation, ce qui permet à un thread bloqué sur un appel à n’importe quel membre de l’objet de continuer.If code in the call stack of a member calls the SignalAndWait method and specifies true for exitContext, the thread exits the synchronization domain, allowing a thread that is blocked on a call to any member of the object to proceed. Lorsque la SignalAndWait méthode est retournée, le thread qui a effectué l’appel doit attendre pour entrer de nouveau dans le domaine de synchronisation.When the SignalAndWait method returns, the thread that made the call must wait to reenter the synchronization domain.

S’applique à

SignalAndWait(WaitHandle, WaitHandle, TimeSpan, Boolean)

Signale un WaitHandle et en attend un autre, en spécifiant le délai sous la forme d’une valeur TimeSpan et en spécifiant s’il faut quitter le domaine de synchronisation du contexte avant de commencer l’attente.Signals one WaitHandle and waits on another, specifying the time-out interval as a TimeSpan and specifying whether to exit the synchronization domain for the context before entering the wait.

public:
 static bool SignalAndWait(System::Threading::WaitHandle ^ toSignal, System::Threading::WaitHandle ^ toWaitOn, TimeSpan timeout, bool exitContext);
public static bool SignalAndWait (System.Threading.WaitHandle toSignal, System.Threading.WaitHandle toWaitOn, TimeSpan timeout, bool exitContext);
static member SignalAndWait : System.Threading.WaitHandle * System.Threading.WaitHandle * TimeSpan * bool -> bool
Public Shared Function SignalAndWait (toSignal As WaitHandle, toWaitOn As WaitHandle, timeout As TimeSpan, exitContext As Boolean) As Boolean

Paramètres

toSignal
WaitHandle

WaitHandle à signaler.The WaitHandle to signal.

toWaitOn
WaitHandle

WaitHandle à attendre.The WaitHandle to wait on.

timeout
TimeSpan

TimeSpan qui représente l'intervalle à attendre.A TimeSpan that represents the interval to wait. Si la valeur est -1, l'attente est infinie.If the value is -1, the wait is infinite.

exitContext
Boolean

true pour quitter le domaine de synchronisation du contexte avant l'attente (dans le cas d'un contexte synchronisé) et l'acquérir à nouveau ensuite ; sinon, false.true to exit the synchronization domain for the context before the wait (if in a synchronized context), and reacquire it afterward; otherwise, false.

Retours

Boolean

true si le signal et l'attente se sont terminés avec succès ou false si le signal s'est terminé mais que l'attente a expiré.true if both the signal and the wait completed successfully, or false if the signal completed but the wait timed out.

Exceptions

toSignal a la valeur null.toSignal is null.

- ou --or- toWaitOn a la valeur null.toWaitOn is null.

La méthode a été appelée sur un thread à l’état STA.The method was called on a thread in STA state.

toSignal est un sémaphore, et possède déjà un nombre complet.toSignal is a semaphore, and it already has a full count.

timeout prend comme valeur un nombre négatif de millièmes de secondes autre que -1.timeout evaluates to a negative number of milliseconds other than -1.

- ou --or- timeout est supérieur à MaxValue.timeout is greater than MaxValue.

L’attente s’est arrêtée, car un thread s’est terminé sans libérer de mutex.The wait completed because a thread exited without releasing a mutex. Cette exception n’est pas levée sur Windows 98 ou Windows Millennium Edition.This exception is not thrown on Windows 98 or Windows Millennium Edition.

Remarques

Il n’est pas garanti que cette opération soit atomique.This operation is not guaranteed to be atomic. Une fois que le thread actuel signale toSignal mais avant qu’il n’attende toWaitOn , un thread qui s’exécute sur un autre processeur peut le signaler toWaitOn ou l’attendre.After the current thread signals toSignal but before it waits on toWaitOn, a thread that is running on another processor might signal toWaitOn or wait on it.

La valeur maximale pour timeout est Int32.MaxValue .The maximum value for timeout is Int32.MaxValue.

Si timeout est égal à zéro, la méthode n’est pas bloquée.If timeout is zero, the method does not block. Il teste l’état de toWaitOn et retourne immédiatement.It tests the state of the toWaitOn and returns immediately.

Remarques sur la sortie du contexteNotes on Exiting the Context

Le exitContext paramètre n’a aucun effet, à moins que la SignalAndWait méthode ne soit appelée à partir d’un contexte managé non défini par défaut.The exitContext parameter has no effect unless the SignalAndWait method is called from inside a nondefault managed context. Cela peut se produire si votre thread est à l’intérieur d’un appel à une instance d’une classe dérivée de ContextBoundObject .This can happen if your thread is inside a call to an instance of a class derived from ContextBoundObject. Même si vous exécutez actuellement une méthode sur une classe qui ne dérive pas de ContextBoundObject , comme String , vous pouvez être dans un contexte non défini par défaut si un ContextBoundObject est sur votre pile dans le domaine d’application actuel.Even if you are currently executing a method on a class that does not derive from ContextBoundObject, like String, you can be in a nondefault context if a ContextBoundObject is on your stack in the current application domain.

Lorsque votre code s’exécute dans un contexte non défini par défaut, true la spécification de pour exitContext oblige le thread à quitter le contexte managé non défini par défaut (c’est-à-dire à passer au contexte par défaut) avant d’exécuter la SignalAndWait méthode.When your code is executing in a nondefault context, specifying true for exitContext causes the thread to exit the nondefault managed context (that is, to transition to the default context) before executing the SignalAndWait method. Le thread retourne au contexte par défaut d’origine une fois l’appel à la SignalAndWait méthode terminé.The thread returns to the original nondefault context after the call to the SignalAndWait method completes.

Cela peut être utile lorsque la classe liée au contexte a SynchronizationAttribute .This can be useful when the context-bound class has SynchronizationAttribute. Dans ce cas, tous les appels aux membres de la classe sont automatiquement synchronisés et le domaine de synchronisation est le corps entier du code pour la classe.In that case, all calls to members of the class are automatically synchronized, and the synchronization domain is the entire body of code for the class. Si le code de la pile des appels d’un membre appelle la SignalAndWait méthode et spécifie true pour exitContext , le thread quitte le domaine de synchronisation, ce qui permet à un thread bloqué sur un appel à n’importe quel membre de l’objet de continuer.If code in the call stack of a member calls the SignalAndWait method and specifies true for exitContext, the thread exits the synchronization domain, allowing a thread that is blocked on a call to any member of the object to proceed. Lorsque la SignalAndWait méthode est retournée, le thread qui a effectué l’appel doit attendre pour entrer de nouveau dans le domaine de synchronisation.When the SignalAndWait method returns, the thread that made the call must wait to reenter the synchronization domain.

S’applique à