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

  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:  SafeTimerHandle
  18. **
  19. **                                                 
  20. **
  21. ** A wrapper for a timer handle
  22. **
  23. ** Date:  July 23, 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 SafeTimerHandle : SafeHandleZeroOrMinusOneIsInvalid
  39.     {
  40.         // Note that CreateWaitableTimer returns 0 on failure
  41.        
  42.         internal SafeTimerHandle() : base(true)
  43.         {
  44.         }
  45.        
  46.         // Not currently used
  47.         //[SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode=true)]
  48.         //internal SafeTimerHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
  49.         // SetHandle(existingHandle);
  50.         //}
  51.        
  52.         [DllImport(ExternDll.Kernel32, ExactSpelling = true, SetLastError = true)]
  53.         [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
  54.         private static extern bool CloseHandle(IntPtr handle);
  55.        
  56.         protected override bool ReleaseHandle()
  57.         {
  58.             return CloseHandle(handle);
  59.         }
  60.     }
  61. }

Developer Fusion