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

  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:  SafeThreadHandle
  18. **
  19. **
  20. ** A wrapper for a thread handle
  21. **
  22. **
  23. ===========================================================*/
  24. using System;
  25. using System.Security;
  26. using System.Diagnostics;
  27. using System.Security.Permissions;
  28. using System.Runtime.InteropServices;
  29. using System.Runtime.CompilerServices;
  30. using Microsoft.Win32;
  31. using Microsoft.Win32.SafeHandles;
  32. using System.Runtime.ConstrainedExecution;
  33. namespace Microsoft.Win32.SafeHandles
  34. {
  35.     [SuppressUnmanagedCodeSecurityAttribute()]
  36.     internal sealed class SafeThreadHandle : SafeHandleZeroOrMinusOneIsInvalid
  37.     {
  38.         internal SafeThreadHandle() : base(true)
  39.         {
  40.         }
  41.        
  42.         internal void InitialSetHandle(IntPtr h)
  43.         {
  44.             Debug.Assert(base.IsInvalid, "Safe handle should only be set once");
  45.             base.SetHandle(h);
  46.         }
  47.        
  48.         protected override bool ReleaseHandle()
  49.         {
  50.             return SafeNativeMethods.CloseHandle(handle);
  51.         }
  52.        
  53.     }
  54. }

Developer Fusion