EventWaitHandle.OpenExisting Método

Definición

Abre un evento de sincronización con nombre especificado, si ya existe.

Sobrecargas

OpenExisting(String)

Abre el evento de sincronización con nombre especificado, si ya existe.

OpenExisting(String, EventWaitHandleRights)

Abre el evento de sincronización con nombre especificado, si ya existe, con el acceso de seguridad deseado.

OpenExisting(String)

Abre el evento de sincronización con nombre especificado, si ya existe.

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

Parámetros

name
String

Nombre del objeto de sincronización que se va a abrir y compartir con otros procesos. El nombre distingue entre mayúsculas y minúsculas.

Devoluciones

EventWaitHandle

Objeto que representa el evento del sistema con nombre.

Atributos

Excepciones

No se puede abrir un objeto de sincronización con el valor name proporcionado. Es posible que no exista o que un objeto de sincronización de un tipo diferente tenga el mismo nombre. En algunos casos, esta excepción se puede producir para nombres no válidos.

name es una cadena vacía.

O bien

Solo .NET Framework: name es mayor que MAX_PATH (260 caracteres).

El valor de name es null.

name no es válido. Esto puede deberse a diversos motivos, incluidas algunas restricciones que puede imponer el sistema operativo, como un prefijo desconocido o caracteres no válidos. Tenga en cuenta que el nombre y los prefijos comunes "Global" y "Local" distinguen mayúsculas de minúsculas.

O bien

Hubo algún otro error. La propiedad HResult puede proporcionar más información.

Solo Windows: name especificó un espacio de nombres desconocido. Consulte Nombres de objetos para obtener más información.

name es demasiado largo. Las restricciones de longitud pueden depender del sistema operativo o la configuración.

El evento con nombre existe, pero el usuario no tiene el acceso de seguridad exigido para utilizarlo.

Comentarios

name puede tener como prefijo Global\ o Local\ especificar un espacio de nombres. Cuando se especifica el Global espacio de nombres, el objeto de sincronización se puede compartir con cualquier proceso del sistema. Cuando se especifica el Local espacio de nombres , que también es el valor predeterminado cuando no se especifica ningún espacio de nombres, el objeto de sincronización se puede compartir con procesos en la misma sesión. En Windows, una sesión es una sesión de inicio de sesión y los servicios normalmente se ejecutan en una sesión no interactiva diferente. En sistemas operativos similares a Unix, cada shell tiene su propia sesión. Los objetos de sincronización local de sesión pueden ser adecuados para sincronizar entre procesos con una relación primaria o secundaria en la que se ejecutan todas en la misma sesión. Para obtener más información sobre los nombres de objetos de sincronización en Windows, vea Nombres de objeto.

Si existe un objeto de sincronización del tipo solicitado en el espacio de nombres , se abre el objeto de sincronización existente. Si un objeto de sincronización no existe en el espacio de nombres o existe un objeto de sincronización de otro tipo en el espacio de nombres , se produce una WaitHandleCannotBeOpenedException excepción .

El OpenExisting método intenta abrir el evento del sistema con nombre especificado. Para crear el evento del sistema cuando aún no existe, use uno de los EventWaitHandle constructores que tiene un name parámetro .

Varias llamadas a este método que usan el mismo valor para name no devuelven necesariamente el mismo EventWaitHandle objeto, aunque los objetos que se devuelven representan el mismo evento del sistema con nombre.

En .NET Framework, esta sobrecarga de método es equivalente a llamar a la sobrecarga del método System.Threading.EventWaitHandle.OpenExisting(System.String,System.Security.AccessControl.EventWaitHandleRights) y especificar EventWaitHandleRights.Synchronize y EventWaitHandleRights.Modify derechos, combinados mediante la operación bit a OR bit.

Especificar la EventWaitHandleRights.Synchronize marca permite a un subproceso esperar en el evento del sistema con nombre y especificar la EventWaitHandleRights.Modify marca permite que un subproceso llame a los Set métodos y Reset .

Consulte también

Se aplica a

OpenExisting(String, EventWaitHandleRights)

Abre el evento de sincronización con nombre especificado, si ya existe, con el acceso de seguridad deseado.

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

Parámetros

name
String

Nombre del objeto de sincronización que se va a abrir y compartir con otros procesos. El nombre distingue entre mayúsculas y minúsculas.

rights
EventWaitHandleRights

Combinación bit a bit de los valores de la enumeración que representan el acceso de seguridad deseado.

Devoluciones

EventWaitHandle

Objeto que representa el evento del sistema con nombre.

Atributos

Excepciones

name es una cadena vacía.

O bien

Solo .NET Framework: name es mayor que MAX_PATH (260 caracteres).

El valor de name es null.

No se puede abrir un objeto de sincronización con el valor name proporcionado. Es posible que no exista o que un objeto de sincronización de un tipo diferente tenga el mismo nombre. En algunos casos, esta excepción se puede producir para nombres no válidos.

name no es válido. Esto puede deberse a diversos motivos, incluidas algunas restricciones que puede imponer el sistema operativo, como un prefijo desconocido o caracteres no válidos. Tenga en cuenta que el nombre y los prefijos comunes "Global" y "Local" distinguen mayúsculas de minúsculas.

O bien

Hubo algún otro error. La propiedad HResult puede proporcionar más información.

Solo Windows: name especificó un espacio de nombres desconocido. Consulte Nombres de objetos para obtener más información.

name es demasiado largo. Las restricciones de longitud pueden depender del sistema operativo o la configuración.

El evento con nombre existe, pero el usuario no tiene el acceso de seguridad deseado.

Ejemplos

En el ejemplo de código siguiente se muestra el comportamiento entre procesos de un evento del sistema con nombre con seguridad de control de acceso. En el ejemplo se usa la sobrecarga del OpenExisting(String) método para probar la existencia de un evento con nombre.

Si el evento no existe, se crea con la propiedad inicial y la seguridad de control de acceso que deniega al usuario actual el derecho de usar el evento, pero concede el derecho de leer y cambiar permisos en el evento.

Si ejecuta el ejemplo compilado desde dos ventanas de comandos, la segunda copia producirá una excepción de infracción de acceso en la llamada a OpenExisting(String). La excepción se detecta y el ejemplo usa la OpenExisting(String, EventWaitHandleRights) sobrecarga del método para esperar en el evento con los derechos necesarios para leer y cambiar los permisos.

Después de cambiar los permisos, el evento se abre con los derechos necesarios para esperar en él y indicarlo. Si ejecuta el ejemplo compilado desde una tercera ventana de comandos, el ejemplo se ejecuta con los nuevos permisos.

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

Comentarios

name puede tener como prefijo Global\ o Local\ especificar un espacio de nombres. Cuando se especifica el Global espacio de nombres, el objeto de sincronización se puede compartir con cualquier proceso del sistema. Cuando se especifica el Local espacio de nombres , que también es el valor predeterminado cuando no se especifica ningún espacio de nombres, el objeto de sincronización se puede compartir con procesos en la misma sesión. En Windows, una sesión es una sesión de inicio de sesión y los servicios normalmente se ejecutan en una sesión no interactiva diferente. En sistemas operativos similares a Unix, cada shell tiene su propia sesión. Los objetos de sincronización local de sesión pueden ser adecuados para sincronizar entre procesos con una relación primaria o secundaria en la que se ejecutan todas en la misma sesión. Para obtener más información sobre los nombres de objetos de sincronización en Windows, vea Nombres de objeto.

Si existe un objeto de sincronización del tipo solicitado en el espacio de nombres , se abre el objeto de sincronización existente. Si un objeto de sincronización no existe en el espacio de nombres o existe un objeto de sincronización de otro tipo en el espacio de nombres , se produce una WaitHandleCannotBeOpenedException excepción .

El rights parámetro debe incluir la EventWaitHandleRights.Synchronize marca para permitir que los subprocesos esperen en el evento y la EventWaitHandleRights.Modify marca para permitir que los subprocesos llamen a los Set métodos y Reset .

El OpenExisting método intenta abrir un evento del sistema con nombre existente. Para crear el evento del sistema cuando aún no existe, use uno de los EventWaitHandle constructores que tiene un name parámetro .

Varias llamadas a este método que usan el mismo valor para name no devuelven necesariamente el mismo EventWaitHandle objeto, aunque los objetos que se devuelven representan el mismo evento del sistema con nombre.

Consulte también

Se aplica a