WpfSafeHandle.cs 602 B

1234567891011121314151617181920212223
  1. using System.Security;
  2. using Microsoft.Win32.SafeHandles;
  3. namespace HandyControl.Tools.Interop;
  4. internal abstract class WpfSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
  5. {
  6. private readonly int _collectorId;
  7. [SecurityCritical]
  8. protected WpfSafeHandle(bool ownsHandle, int collectorId) : base(ownsHandle)
  9. {
  10. HandleCollector.Add(collectorId);
  11. _collectorId = collectorId;
  12. }
  13. [SecurityCritical, SecuritySafeCritical]
  14. protected override void Dispose(bool disposing)
  15. {
  16. HandleCollector.Remove(_collectorId);
  17. base.Dispose(disposing);
  18. }
  19. }