EventWaitHandle.OpenExisting Méthode

Définition

Ouvre un événement de synchronisation nommé spécifié s'il existe déjà.

Surcharges

OpenExisting(String)

Ouvre l'événement de synchronisation nommé spécifié s'il existe déjà.

OpenExisting(String, EventWaitHandleRights)

Ouvre l'événement de synchronisation nommé spécifié, s'il existe déjà, avec l'accès de sécurité souhaité.

OpenExisting(String)

Ouvre l'événement de synchronisation nommé spécifié s'il existe déjà.

public:
 static System::Threading::EventWaitHandle ^ OpenExisting(System::String ^ name);
[System.Security.SecurityCritical]
public static System.Threading.EventWaitHandle OpenExisting (string name);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Threading.EventWaitHandle OpenExisting (string name);
public static System.Threading.EventWaitHandle OpenExisting (string name);
[<System.Security.SecurityCritical>]
static member OpenExisting : string -> System.Threading.EventWaitHandle
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member OpenExisting : string -> System.Threading.EventWaitHandle
static member OpenExisting : string -> System.Threading.EventWaitHandle
Public Shared Function OpenExisting (name As String) As EventWaitHandle

Paramètres

name
String

Nom de l’objet de synchronisation à ouvrir et à partager avec d’autres processus. Le nom respecte la casse.

Retours

EventWaitHandle

Objet qui représente l'événement système nommé.

Attributs

Exceptions

Il n’est pas possible d’ouvrir un objet de synchronisation portant le name fourni. Il est possible qu’il n’existe pas ou qu’un objet de synchronisation d’un autre type possède le même nom. Il peut arriver que cette exception soit levée en raison d’un nom non valide.

name est une chaîne vide.

  • ou -

.NET Framework uniquement : name est plus long que MAX_PATH (260 caractères).

name est null.

name n'est pas valide. Il peut y avoir diverses raisons à cela, notamment des restrictions placées par le système d’exploitation (par exemple, un préfixe inconnu ou des caractères non valides). Remarque : le nom et les préfixes communs « Global » et « Local » respectent la casse.

  • ou -

Il y avait une autre erreur. La propriété HResult est susceptible de fournir plus d’informations.

Windows uniquement : name spécifié un espace de noms inconnu. Pour plus d’informations, consultez Noms d’objets.

name est trop long. Les restrictions de longueur peuvent dépendre du système d’exploitation ou de la configuration.

L'événement nommé existe, mais l'utilisateur ne possède pas l'accès de sécurité requis pour l'utiliser.

Remarques

Le name préfixe peut être avec Global\ ou Local\ pour spécifier un espace de noms. Lorsque l’espace Global de noms est spécifié, l’objet de synchronisation peut être partagé avec tous les processus sur le système. Lorsque l’espace Local de noms est spécifié, qui est également la valeur par défaut lorsqu’aucun espace de noms n’est spécifié, l’objet de synchronisation peut être partagé avec des processus dans la même session. Sur Windows, une session est une session de connexion, et les services s’exécutent généralement dans une autre session non interactive. Sur les systèmes d’exploitation de type Unix, chaque interpréteur de commandes possède sa propre session. Les objets de synchronisation locale de session peuvent être appropriés pour la synchronisation entre les processus avec une relation parent/enfant où ils s’exécutent tous dans la même session. Pour plus d’informations sur les noms d’objets de synchronisation sur Windows, consultez Noms d’objets.

Si un objet de synchronisation du type demandé existe dans l’espace de noms, l’objet de synchronisation existant est ouvert. Si un objet de synchronisation n’existe pas dans l’espace de noms ou qu’un objet de synchronisation d’un type différent existe dans l’espace de noms, un WaitHandleCannotBeOpenedException objet est levée.

La OpenExisting méthode tente d’ouvrir l’événement système nommé spécifié. Pour créer l’événement système lorsqu’il n’existe pas déjà, utilisez l’un EventWaitHandle des constructeurs qui ont un name paramètre.

Plusieurs appels à cette méthode qui utilisent la même valeur ne name retournent pas nécessairement le même EventWaitHandle objet, même si les objets retournés représentent le même événement système nommé.

Dans .NET Framework, cette surcharge de méthode équivaut à appeler la surcharge de méthode System.Threading.EventWaitHandle.OpenExisting(System.String,System.Security.AccessControl.EventWaitHandleRights) surcharge et spécification EventWaitHandleRights.Synchronize et EventWaitHandleRights.Modify droits, combinés à l’aide de l’opération au niveau OR du bit.

La spécification de l’indicateur EventWaitHandleRights.Synchronize permet à un thread d’attendre sur l’événement système nommé et de spécifier l’indicateur EventWaitHandleRights.Modify permet à un thread d’appeler les méthodes et Reset les Set méthodes.

Voir aussi

S’applique à

OpenExisting(String, EventWaitHandleRights)

Ouvre l'événement de synchronisation nommé spécifié, s'il existe déjà, avec l'accès de sécurité souhaité.

public:
 static System::Threading::EventWaitHandle ^ OpenExisting(System::String ^ name, System::Security::AccessControl::EventWaitHandleRights rights);
public static System.Threading.EventWaitHandle OpenExisting (string name, System.Security.AccessControl.EventWaitHandleRights rights);
[System.Security.SecurityCritical]
public static System.Threading.EventWaitHandle OpenExisting (string name, System.Security.AccessControl.EventWaitHandleRights rights);
static member OpenExisting : string * System.Security.AccessControl.EventWaitHandleRights -> System.Threading.EventWaitHandle
[<System.Security.SecurityCritical>]
static member OpenExisting : string * System.Security.AccessControl.EventWaitHandleRights -> System.Threading.EventWaitHandle
Public Shared Function OpenExisting (name As String, rights As EventWaitHandleRights) As EventWaitHandle

Paramètres

name
String

Nom de l’objet de synchronisation à ouvrir et à partager avec d’autres processus. Le nom respecte la casse.

rights
EventWaitHandleRights

Combinaison d'opérations de bits des valeurs d'énumération qui représentent l'accès de sécurité voulu.

Retours

EventWaitHandle

Objet qui représente l'événement système nommé.

Attributs

Exceptions

name est une chaîne vide.

  • ou -

.NET Framework uniquement : name est plus long que MAX_PATH (260 caractères).

name est null.

Il n’est pas possible d’ouvrir un objet de synchronisation portant le name fourni. Il est possible qu’il n’existe pas ou qu’un objet de synchronisation d’un autre type possède le même nom. Il peut arriver que cette exception soit levée en raison d’un nom non valide.

name n'est pas valide. Il peut y avoir diverses raisons à cela, notamment des restrictions placées par le système d’exploitation (par exemple, un préfixe inconnu ou des caractères non valides). Remarque : le nom et les préfixes communs « Global » et « Local » respectent la casse.

  • ou -

Il y avait une autre erreur. La propriété HResult est susceptible de fournir plus d’informations.

Windows uniquement : name spécifié un espace de noms inconnu. Pour plus d’informations, consultez Noms d’objets.

name est trop long. Les restrictions de longueur peuvent dépendre du système d’exploitation ou de la configuration.

L’événement nommé existe mais l’utilisateur ne dispose de l’accès de sécurité nécessaire.

Exemples

L’exemple de code suivant illustre le comportement inter-processus d’un événement système nommé avec la sécurité du contrôle d’accès. L’exemple utilise la OpenExisting(String) surcharge de méthode pour tester l’existence d’un événement nommé.

Si l’événement n’existe pas, il est créé avec la propriété initiale et la sécurité du contrôle d’accès qui refuse à l’utilisateur actuel le droit d’utiliser l’événement, mais accorde le droit de lire et de modifier les autorisations sur l’événement.

Si vous exécutez l’exemple compilé à partir de deux fenêtres de commandes, la deuxième copie lève une exception de violation d’accès sur l’appel à OpenExisting(String). L’exception est interceptée et l’exemple utilise la OpenExisting(String, EventWaitHandleRights) surcharge de méthode pour attendre l’événement avec les droits nécessaires pour lire et modifier les autorisations.

Une fois les autorisations modifiées, l’événement est ouvert avec les droits nécessaires pour attendre et le signaler. Si vous exécutez l’exemple compilé à partir d’une troisième fenêtre de commande, l’exemple s’exécute à l’aide des nouvelles autorisations.

using namespace System;
using namespace System::Threading;
using namespace System::Security::AccessControl;
using namespace System::Security::Permissions;

public ref class Example
{
public:
   [SecurityPermissionAttribute(SecurityAction::Demand,Flags=SecurityPermissionFlag::UnmanagedCode)]
   static void Main()
   {
      String^ ewhName = L"EventWaitHandleExample5";

      EventWaitHandle^ ewh = nullptr;
      bool doesNotExist = false;
      bool unauthorized = false;
      
      // The value of this variable is set by the event
      // constructor. It is true if the named system event was
      // created, and false if the named event already existed.
      //
      bool wasCreated;
      
      // Attempt to open the named event.
      try
      {
         // Open the event with (EventWaitHandleRights.Synchronize
         // | EventWaitHandleRights.Modify), to wait on and
         // signal the named event.
         //
         ewh = EventWaitHandle::OpenExisting( ewhName );
      }
      catch ( WaitHandleCannotBeOpenedException^ ) 
      {
         Console::WriteLine( L"Named event does not exist." );
         doesNotExist = true;
      }
      catch ( UnauthorizedAccessException^ ex ) 
      {
         Console::WriteLine( L"Unauthorized access: {0}", ex->Message );
         unauthorized = true;
      }

      // There are three cases: (1) The event does not exist.
      // (2) The event exists, but the current user doesn't
      // have access. (3) The event exists and the user has
      // access.
      //
      if ( doesNotExist )
      {
         // The event does not exist, so create it.

         // Create an access control list (ACL) that denies the
         // current user the right to wait on or signal the
         // event, but allows the right to read and change
         // security information for the event.
         //
         String^ user = String::Concat( Environment::UserDomainName, L"\\",
            Environment::UserName );
         EventWaitHandleSecurity^ ewhSec = gcnew EventWaitHandleSecurity;
         //following constructor fails
         EventWaitHandleAccessRule^ rule = gcnew EventWaitHandleAccessRule(
            user,
            static_cast<EventWaitHandleRights>(
               EventWaitHandleRights::Synchronize | 
               EventWaitHandleRights::Modify),
            AccessControlType::Deny );
         ewhSec->AddAccessRule( rule );

         rule = gcnew EventWaitHandleAccessRule( user,
            static_cast<EventWaitHandleRights>(
               EventWaitHandleRights::ReadPermissions | 
               EventWaitHandleRights::ChangePermissions),
            AccessControlType::Allow );
         ewhSec->AddAccessRule( rule );
         
         // Create an EventWaitHandle object that represents
         // the system event named by the constant 'ewhName',
         // initially signaled, with automatic reset, and with
         // the specified security access. The Boolean value that
         // indicates creation of the underlying system object
         // is placed in wasCreated.
         //
         ewh = gcnew EventWaitHandle( true,
            EventResetMode::AutoReset,
            ewhName,
            wasCreated,
            ewhSec );
         
         // If the named system event was created, it can be
         // used by the current instance of this program, even
         // though the current user is denied access. The current
         // program owns the event. Otherwise, exit the program.
         //
         if ( wasCreated )
         {
            Console::WriteLine( L"Created the named event." );
         }
         else
         {
            Console::WriteLine( L"Unable to create the event." );
            return;
         }
      }
      else if ( unauthorized )
      {
         // Open the event to read and change the access control
         // security. The access control security defined above
         // allows the current user to do this.
         //
         try
         {
            ewh = EventWaitHandle::OpenExisting( ewhName, 
               static_cast<EventWaitHandleRights>(
                  EventWaitHandleRights::ReadPermissions |
                  EventWaitHandleRights::ChangePermissions) );
            
            // Get the current ACL. This requires
            // EventWaitHandleRights.ReadPermissions.
            EventWaitHandleSecurity^ ewhSec = ewh->GetAccessControl();
            String^ user = String::Concat( Environment::UserDomainName, L"\\",
               Environment::UserName );
            
            // First, the rule that denied the current user
            // the right to enter and release the event must
            // be removed.
            EventWaitHandleAccessRule^ rule = gcnew EventWaitHandleAccessRule(
               user,
               static_cast<EventWaitHandleRights>(
                  EventWaitHandleRights::Synchronize |
                  EventWaitHandleRights::Modify),
               AccessControlType::Deny );
            ewhSec->RemoveAccessRule( rule );
            
            // Now grant the user the correct rights.
            //
            rule = gcnew EventWaitHandleAccessRule( user,
               static_cast<EventWaitHandleRights>(
                  EventWaitHandleRights::Synchronize |
                  EventWaitHandleRights::Modify),
               AccessControlType::Allow );
            ewhSec->AddAccessRule( rule );
            
            // Update the ACL. This requires
            // EventWaitHandleRights.ChangePermissions.
            ewh->SetAccessControl( ewhSec );
            Console::WriteLine( L"Updated event security." );
            
            // Open the event with (EventWaitHandleRights.Synchronize
            // | EventWaitHandleRights.Modify), the rights required
            // to wait on and signal the event.
            //
            ewh = EventWaitHandle::OpenExisting( ewhName );
         }
         catch ( UnauthorizedAccessException^ ex ) 
         {
            Console::WriteLine( L"Unable to change permissions: {0}",
               ex->Message );
            return;
         }

      }
      
      // Wait on the event, and hold it until the program
      // exits.
      //
      try
      {
         Console::WriteLine( L"Wait on the event." );
         ewh->WaitOne();
         Console::WriteLine( L"Event was signaled." );
         Console::WriteLine( L"Press the Enter key to signal the event and exit." );
         Console::ReadLine();
      }
      catch ( UnauthorizedAccessException^ ex ) 
      {
         Console::WriteLine( L"Unauthorized access: {0}", ex->Message );
      }
      finally
      {
         ewh->Set();
      }
   }
};

int main()
{
   Example::Main();
}
using System;
using System.Threading;
using System.Security.AccessControl;

internal class Example
{
    internal static void Main()
    {
        const string ewhName = "EventWaitHandleExample5";

        EventWaitHandle ewh = null;
        bool doesNotExist = false;
        bool unauthorized = false;

        // The value of this variable is set by the event
        // constructor. It is true if the named system event was
        // created, and false if the named event already existed.
        //
        bool wasCreated;

        // Attempt to open the named event.
        try
        {
            // Open the event with (EventWaitHandleRights.Synchronize
            // | EventWaitHandleRights.Modify), to wait on and 
            // signal the named event.
            //
            ewh = EventWaitHandle.OpenExisting(ewhName);
        }
        catch (WaitHandleCannotBeOpenedException)
        {
            Console.WriteLine("Named event does not exist.");
            doesNotExist = true;
        }
        catch (UnauthorizedAccessException ex)
        {
            Console.WriteLine("Unauthorized access: {0}", ex.Message);
            unauthorized = true;
        }

        // There are three cases: (1) The event does not exist.
        // (2) The event exists, but the current user doesn't 
        // have access. (3) The event exists and the user has
        // access.
        //
        if (doesNotExist)
        {
            // The event does not exist, so create it.

            // Create an access control list (ACL) that denies the
            // current user the right to wait on or signal the 
            // event, but allows the right to read and change
            // security information for the event.
            //
            string user = Environment.UserDomainName + "\\"
                + Environment.UserName;
            EventWaitHandleSecurity ewhSec = 
                new EventWaitHandleSecurity();

            EventWaitHandleAccessRule rule = 
                new EventWaitHandleAccessRule(user, 
                    EventWaitHandleRights.Synchronize | 
                    EventWaitHandleRights.Modify, 
                    AccessControlType.Deny);
            ewhSec.AddAccessRule(rule);

            rule = new EventWaitHandleAccessRule(user, 
                EventWaitHandleRights.ReadPermissions | 
                EventWaitHandleRights.ChangePermissions, 
                AccessControlType.Allow);
            ewhSec.AddAccessRule(rule);

            // Create an EventWaitHandle object that represents
            // the system event named by the constant 'ewhName', 
            // initially signaled, with automatic reset, and with
            // the specified security access. The Boolean value that 
            // indicates creation of the underlying system object
            // is placed in wasCreated.
            //
            ewh = new EventWaitHandle(true, 
                EventResetMode.AutoReset, 
                ewhName, 
                out wasCreated, 
                ewhSec);

            // If the named system event was created, it can be
            // used by the current instance of this program, even 
            // though the current user is denied access. The current
            // program owns the event. Otherwise, exit the program.
            // 
            if (wasCreated)
            {
                Console.WriteLine("Created the named event.");
            }
            else
            {
                Console.WriteLine("Unable to create the event.");
                return;
            }
        }
        else if (unauthorized)
        {
            // Open the event to read and change the access control
            // security. The access control security defined above
            // allows the current user to do this.
            //
            try
            {
                ewh = EventWaitHandle.OpenExisting(ewhName, 
                    EventWaitHandleRights.ReadPermissions | 
                    EventWaitHandleRights.ChangePermissions);

                // Get the current ACL. This requires 
                // EventWaitHandleRights.ReadPermissions.
                EventWaitHandleSecurity ewhSec = ewh.GetAccessControl();
                
                string user = Environment.UserDomainName + "\\"
                    + Environment.UserName;

                // First, the rule that denied the current user 
                // the right to enter and release the event must
                // be removed.
                EventWaitHandleAccessRule rule = 
                    new EventWaitHandleAccessRule(user, 
                        EventWaitHandleRights.Synchronize | 
                        EventWaitHandleRights.Modify, 
                        AccessControlType.Deny);
                ewhSec.RemoveAccessRule(rule);

                // Now grant the user the correct rights.
                // 
                rule = new EventWaitHandleAccessRule(user, 
                    EventWaitHandleRights.Synchronize | 
                    EventWaitHandleRights.Modify, 
                    AccessControlType.Allow);
                ewhSec.AddAccessRule(rule);

                // Update the ACL. This requires
                // EventWaitHandleRights.ChangePermissions.
                ewh.SetAccessControl(ewhSec);

                Console.WriteLine("Updated event security.");

                // Open the event with (EventWaitHandleRights.Synchronize 
                // | EventWaitHandleRights.Modify), the rights required
                // to wait on and signal the event.
                //
                ewh = EventWaitHandle.OpenExisting(ewhName);
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine("Unable to change permissions: {0}",
                    ex.Message);
                return;
            }
        }

        // Wait on the event, and hold it until the program
        // exits.
        //
        try
        {
            Console.WriteLine("Wait on the event.");
            ewh.WaitOne();
            Console.WriteLine("Event was signaled.");
            Console.WriteLine("Press the Enter key to signal the event and exit.");
            Console.ReadLine();
        }
        catch (UnauthorizedAccessException ex)
        {
            Console.WriteLine("Unauthorized access: {0}", ex.Message);
        }
        finally
        {
            ewh.Set();
        }
    }
}
Imports System.Threading
Imports System.Security.AccessControl

Friend Class Example

    <MTAThread> _
    Friend Shared Sub Main()
        Const ewhName As String = "EventWaitHandleExample5"

        Dim ewh As EventWaitHandle = Nothing
        Dim doesNotExist as Boolean = False
        Dim unauthorized As Boolean = False

        ' The value of this variable is set by the event
        ' constructor. It is True if the named system event was
        ' created, and False if the named event already existed.
        '
        Dim wasCreated As Boolean

        ' Attempt to open the named event.
        Try
            ' Open the event with (EventWaitHandleRights.Synchronize
            ' Or EventWaitHandleRights.Modify), to wait on and 
            ' signal the named event.
            '
            ewh = EventWaitHandle.OpenExisting(ewhName)
        Catch ex As WaitHandleCannotBeOpenedException
            Console.WriteLine("Named event does not exist.")
            doesNotExist = True
        Catch ex As UnauthorizedAccessException
            Console.WriteLine("Unauthorized access: {0}", ex.Message)
            unauthorized = True
        End Try

        ' There are three cases: (1) The event does not exist.
        ' (2) The event exists, but the current user doesn't 
        ' have access. (3) The event exists and the user has
        ' access.
        '
        If doesNotExist Then
            ' The event does not exist, so create it.

            ' Create an access control list (ACL) that denies the
            ' current user the right to wait on or signal the 
            ' event, but allows the right to read and change
            ' security information for the event.
            '
            Dim user As String = Environment.UserDomainName _ 
                & "\" & Environment.UserName
            Dim ewhSec As New EventWaitHandleSecurity()

            Dim rule As New EventWaitHandleAccessRule(user, _
                EventWaitHandleRights.Synchronize Or _
                EventWaitHandleRights.Modify, _
                AccessControlType.Deny)
            ewhSec.AddAccessRule(rule)

            rule = New EventWaitHandleAccessRule(user, _
                EventWaitHandleRights.ReadPermissions Or _
                EventWaitHandleRights.ChangePermissions, _
                AccessControlType.Allow)
            ewhSec.AddAccessRule(rule)

            ' Create an EventWaitHandle object that represents
            ' the system event named by the constant 'ewhName', 
            ' initially signaled, with automatic reset, and with
            ' the specified security access. The Boolean value that 
            ' indicates creation of the underlying system object
            ' is placed in wasCreated.
            '
            ewh = New EventWaitHandle(True, _
                EventResetMode.AutoReset, ewhName, _
                wasCreated, ewhSec)

            ' If the named system event was created, it can be
            ' used by the current instance of this program, even 
            ' though the current user is denied access. The current
            ' program owns the event. Otherwise, exit the program.
            ' 
            If wasCreated Then
                Console.WriteLine("Created the named event.")
            Else
                Console.WriteLine("Unable to create the event.")
                Return
            End If

        ElseIf unauthorized Then

            ' Open the event to read and change the access control
            ' security. The access control security defined above
            ' allows the current user to do this.
            '
            Try
                ewh = EventWaitHandle.OpenExisting(ewhName, _
                    EventWaitHandleRights.ReadPermissions Or _
                    EventWaitHandleRights.ChangePermissions)

                ' Get the current ACL. This requires 
                ' EventWaitHandleRights.ReadPermissions.
                Dim ewhSec As EventWaitHandleSecurity = _
                    ewh.GetAccessControl()
                
                Dim user As String = Environment.UserDomainName _ 
                    & "\" & Environment.UserName

                ' First, the rule that denied the current user 
                ' the right to enter and release the event must
                ' be removed.
                Dim rule As New EventWaitHandleAccessRule(user, _
                    EventWaitHandleRights.Synchronize Or _
                    EventWaitHandleRights.Modify, _
                    AccessControlType.Deny)
                ewhSec.RemoveAccessRule(rule)

                ' Now grant the user the correct rights.
                ' 
                rule = New EventWaitHandleAccessRule(user, _
                    EventWaitHandleRights.Synchronize Or _
                    EventWaitHandleRights.Modify, _
                    AccessControlType.Allow)
                ewhSec.AddAccessRule(rule)

                ' Update the ACL. This requires
                ' EventWaitHandleRights.ChangePermissions.
                ewh.SetAccessControl(ewhSec)

                Console.WriteLine("Updated event security.")

                ' Open the event with (EventWaitHandleRights.Synchronize 
                ' Or EventWaitHandleRights.Modify), the rights required
                ' to wait on and signal the event.
                '
                ewh = EventWaitHandle.OpenExisting(ewhName)

            Catch ex As UnauthorizedAccessException
                Console.WriteLine("Unable to change permissions: {0}", _
                    ex.Message)
                Return
            End Try

        End If

        ' Wait on the event, and hold it until the program
        ' exits.
        '
        Try
            Console.WriteLine("Wait on the event.")
            ewh.WaitOne()
            Console.WriteLine("Event was signaled.")
            Console.WriteLine("Press the Enter key to signal the event and exit.")
            Console.ReadLine()
        Catch ex As UnauthorizedAccessException
            Console.WriteLine("Unauthorized access: {0}", _
                ex.Message)
        Finally
            ewh.Set()
        End Try
    End Sub 
End Class

Remarques

Le name préfixe peut être associé Global\ ou Local\ spécifier un espace de noms. Lorsque l’espace Global de noms est spécifié, l’objet de synchronisation peut être partagé avec tous les processus sur le système. Lorsque l’espace Local de noms est spécifié, qui est également la valeur par défaut lorsqu’aucun espace de noms n’est spécifié, l’objet de synchronisation peut être partagé avec des processus dans la même session. Sur Windows, une session est une session de connexion et les services s’exécutent généralement dans une autre session non interactive. Sur les systèmes d’exploitation de type Unix, chaque interpréteur de commandes a sa propre session. Les objets de synchronisation local de session peuvent être appropriés pour synchroniser entre les processus avec une relation parent/enfant où ils s’exécutent tous dans la même session. Pour plus d’informations sur les noms d’objets de synchronisation sur Windows, consultez Noms d’objets.

Si un objet de synchronisation du type demandé existe dans l’espace de noms, l’objet de synchronisation existant est ouvert. Si un objet de synchronisation n’existe pas dans l’espace de noms ou si un objet de synchronisation d’un autre type existe dans l’espace de noms, un WaitHandleCannotBeOpenedException objet est levée.

Le rights paramètre doit inclure l’indicateur EventWaitHandleRights.Synchronize pour autoriser les threads à attendre sur l’événement, et l’indicateur EventWaitHandleRights.Modify pour autoriser les threads à appeler et Set Reset les méthodes.

La OpenExisting méthode tente d’ouvrir un événement système nommé existant. Pour créer l’événement système lorsqu’il n’existe pas encore, utilisez l’un des EventWaitHandle constructeurs qui ont un name paramètre.

Plusieurs appels à cette méthode qui utilisent la même valeur pour name ne retournent pas nécessairement le même EventWaitHandle objet, même si les objets retournés représentent le même événement système nommé.

Voir aussi

S’applique à