The Labs \ Source Viewer \ SSCLI \ Microsoft.Win32.SafeHandles \ SafeEventHandle

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*============================================================
  16. **
  17. ** Class:  SafeEventHandle
  18. **
  19. **                                                 
  20. **
  21. ** A wrapper for a win32 event handles
  22. **
  23. ** Date:  July 8, 2002
  24. **
  25. ===========================================================*/
  26. using System;
  27. using System.Security;
  28. using System.Security.Permissions;
  29. using System.Runtime.InteropServices;
  30. using System.Runtime.CompilerServices;
  31. using Microsoft.Win32;
  32. using Microsoft.Win32.SafeHandles;
  33. using System.Runtime.ConstrainedExecution;
  34. namespace Microsoft.Win32.SafeHandles
  35. {
  36.     [HostProtectionAttribute(MayLeakOnAbort = true)]
  37.     [SuppressUnmanagedCodeSecurityAttribute()]
  38.     internal sealed class SafeEventHandle : SafeHandleZeroOrMinusOneIsInvalid
  39.     {
  40.         // Note that CreateEvent returns 0 on failure
  41.        
  42.         internal SafeEventHandle() : base(true)
  43.         {
  44.         }
  45.        
  46.         [DllImport(ExternDll.Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Unicode)]
  47.         static internal extern SafeEventHandle CreateEvent(HandleRef lpEventAttributes, bool bManualReset, bool bInitialState, string name);
  48.        
  49.         [DllImport(ExternDll.Kernel32, ExactSpelling = true, SetLastError = true)]
  50.         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
  51.         private static extern bool CloseHandle(IntPtr handle);
  52.        
  53.         protected override bool ReleaseHandle()
  54.         {
  55.             return CloseHandle(handle);
  56.         }
  57.     }
  58. }

Developer Fusion