EventWaitHandle.OpenExisting Metodo

Definizione

Apre un evento di sincronizzazione denominato specificato, se esistente.

Overload

OpenExisting(String)

Apre l'evento di sincronizzazione denominato specificato, se esistente.

OpenExisting(String, EventWaitHandleRights)

Apre l'evento di sincronizzazione denominato specificato, se esistente, con l'accesso di sicurezza desiderato.

OpenExisting(String)

Apre l'evento di sincronizzazione denominato specificato, se esistente.

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

Parametri

name
String

Nome dell'oggetto di sincronizzazione da aprire e condividere con altri processi. Per il nome è prevista la distinzione tra maiuscole e minuscole.

Restituisce

EventWaitHandle

Oggetto che rappresenta l'evento di sistema denominato.

Attributi

Eccezioni

Non è possibile aprire un oggetto di sincronizzazione con l'elemento name specificato. È possibile che non esista o che un oggetto di sincronizzazione di un tipo diverso abbia lo stesso nome. In alcuni casi, questa eccezione può essere generata per i nomi non validi.

Il parametro name è una stringa vuota.

-oppure-

Solo .NET Framework: la lunghezza di name supera MAX_PATH (260 caratteri).

name costruito in modo predefinito è null.

name non è valido. I motivi possono essere diversi, e tra questi limitazioni implementate dal sistema operativo, come prefisso sconosciuto o caratteri non validi. Si noti che il nome e i prefissi comuni "Global" e "Local" rilevano la distinzione maiuscole/minuscole.

-oppure-

Si è verificato un altro errore. È possibile che la proprietà HResult offra ulteriori informazioni.

Solo Windows: name ha specificato uno spazio dei nomi sconosciuto. Per altre informazioni, vedere Object Names (Nomi oggetti).

name supera la lunghezza consentita. Le limitazioni di lunghezza possono dipendere dal sistema operativo o dalla configurazione.

L'evento denominato esiste, ma l'utente non dispone dell'accesso di sicurezza necessario per utilizzarlo.

Commenti

Può name essere preceduto Global\ da o Local\ per specificare uno spazio dei nomi. Quando si specifica lo Global spazio dei nomi, l'oggetto di sincronizzazione può essere condiviso con tutti i processi nel sistema. Quando si specifica lo Local spazio dei nomi , che è anche l'impostazione predefinita quando non viene specificato alcuno spazio dei nomi, l'oggetto di sincronizzazione può essere condiviso con i processi nella stessa sessione. In Windows una sessione è una sessione di accesso e i servizi vengono in genere eseguiti in una sessione diversa non interattiva. Nei sistemi operativi simili a Unix, ogni shell ha una sessione specifica. Gli oggetti di sincronizzazione locale della sessione possono essere appropriati per la sincronizzazione tra processi con una relazione padre/figlio in cui vengono eseguiti tutti nella stessa sessione. Per altre informazioni sui nomi degli oggetti di sincronizzazione in Windows, vedere Nomi di oggetti.

Se nello spazio dei nomi esiste un oggetto di sincronizzazione del tipo richiesto, viene aperto l'oggetto di sincronizzazione esistente. Se non esiste un oggetto di sincronizzazione nello spazio dei nomi o se esiste un oggetto di sincronizzazione di un tipo diverso nello spazio dei nomi , viene generata un'eccezione WaitHandleCannotBeOpenedException .

Il OpenExisting metodo tenta di aprire l'evento di sistema denominato specificato. Per creare l'evento di sistema quando non esiste già, usare uno dei EventWaitHandle costruttori con un name parametro .

Più chiamate a questo metodo che usano lo stesso valore per name non restituiscono necessariamente lo stesso EventWaitHandle oggetto, anche se gli oggetti restituiti rappresentano lo stesso evento di sistema denominato.

In .NET Framework questo overload di metodo equivale a chiamare l'overload del metodo System.Threading.EventWaitHandle.OpenExisting(System.String,System.Security.AccessControl.EventWaitHandleRights) e specificare EventWaitHandleRights.Synchronize e EventWaitHandleRights.Modify diritti, combinati usando l'operazione bit per OR bit.

La specifica del EventWaitHandleRights.Synchronize flag consente a un thread di attendere l'evento di sistema denominato e specificare il EventWaitHandleRights.Modify flag consente a un thread di chiamare i Set metodi e Reset .

Vedi anche

Si applica a

OpenExisting(String, EventWaitHandleRights)

Apre l'evento di sincronizzazione denominato specificato, se esistente, con l'accesso di sicurezza desiderato.

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

Parametri

name
String

Nome dell'oggetto di sincronizzazione da aprire e condividere con altri processi. Per il nome è prevista la distinzione tra maiuscole e minuscole.

rights
EventWaitHandleRights

Combinazione bit per bit dei valori di enumerazione che rappresentano l'accesso di sicurezza desiderato.

Restituisce

EventWaitHandle

Oggetto che rappresenta l'evento di sistema denominato.

Attributi

Eccezioni

Il parametro name è una stringa vuota.

-oppure-

Solo .NET Framework: la lunghezza di name supera MAX_PATH (260 caratteri).

name costruito in modo predefinito è null.

Non è possibile aprire un oggetto di sincronizzazione con l'elemento name specificato. È possibile che non esista o che un oggetto di sincronizzazione di un tipo diverso abbia lo stesso nome. In alcuni casi, questa eccezione può essere generata per i nomi non validi.

name non è valido. I motivi possono essere diversi, e tra questi limitazioni implementate dal sistema operativo, come prefisso sconosciuto o caratteri non validi. Si noti che il nome e i prefissi comuni "Global" e "Local" rilevano la distinzione maiuscole/minuscole.

-oppure-

Si è verificato un altro errore. È possibile che la proprietà HResult offra ulteriori informazioni.

Solo Windows: name ha specificato uno spazio dei nomi sconosciuto. Per altre informazioni, vedere Object Names (Nomi oggetti).

name supera la lunghezza consentita. Le limitazioni di lunghezza possono dipendere dal sistema operativo o dalla configurazione.

L'evento denominato esiste, ma l'utente non dispone dell'accesso di sicurezza desiderato.

Esempio

Nell'esempio di codice seguente viene illustrato il comportamento tra processi di un evento di sistema denominato con sicurezza del controllo di accesso. L'esempio usa l'overload del OpenExisting(String) metodo per testare l'esistenza di un evento denominato.

Se l'evento non esiste, viene creato con la proprietà iniziale e la sicurezza del controllo di accesso che nega all'utente corrente il diritto di usare l'evento, ma concede il diritto di leggere e modificare le autorizzazioni per l'evento.

Se si esegue l'esempio compilato da due finestre di comando, la seconda copia genererà un'eccezione di violazione di accesso nella chiamata a OpenExisting(String). L'eccezione viene rilevata e l'esempio usa l'overload del OpenExisting(String, EventWaitHandleRights) metodo per attendere l'evento con i diritti necessari per leggere e modificare le autorizzazioni.

Dopo aver modificato le autorizzazioni, l'evento viene aperto con i diritti necessari per attendere e segnalarlo. Se si esegue l'esempio compilato da una terza finestra di comando, l'esempio viene eseguito usando le nuove autorizzazioni.

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

Commenti

Può name essere preceduto da Global\ o Local\ per specificare uno spazio dei nomi. Quando viene specificato lo spazio dei nomi, l'oggetto Global di sincronizzazione può essere condiviso con tutti i processi nel sistema. Quando viene specificato lo Local spazio dei nomi, che è anche il valore predefinito quando non viene specificato alcun spazio dei nomi, l'oggetto di sincronizzazione può essere condiviso con i processi nella stessa sessione. In Windows una sessione è una sessione di accesso e i servizi vengono in genere eseguiti in una sessione non interattiva diversa. Nei sistemi operativi Unix, ogni shell ha la propria sessione. Gli oggetti di sincronizzazione locale della sessione possono essere appropriati per la sincronizzazione tra processi con una relazione padre/figlio in cui vengono eseguiti tutti nella stessa sessione. Per altre informazioni sui nomi degli oggetti di sincronizzazione in Windows, vedere Nomi oggetti.

Se esiste un oggetto di sincronizzazione del tipo richiesto nello spazio dei nomi, l'oggetto di sincronizzazione esistente viene aperto. Se un oggetto di sincronizzazione non esiste nello spazio dei nomi o un oggetto di sincronizzazione di un tipo diverso esiste nello spazio dei nomi, viene generato un WaitHandleCannotBeOpenedException oggetto.

Il rights parametro deve includere il EventWaitHandleRights.Synchronize flag per consentire ai thread di attendere l'evento e il EventWaitHandleRights.Modify flag per consentire ai thread di chiamare i Set metodi e Reset .

Il OpenExisting metodo tenta di aprire un evento denominato esistente. Per creare l'evento di sistema quando non esiste già, usare uno dei EventWaitHandle costruttori con un name parametro.

Più chiamate a questo metodo che usano lo stesso valore per name non restituiscono necessariamente lo stesso EventWaitHandle oggetto, anche se gli oggetti restituiti rappresentano lo stesso evento di sistema denominato.

Vedi anche

Si applica a