Adding reference source for System.Net
[mono.git] / mcs / class / referencesource / System / net / System / Net / NetworkInformation / SafeCancelMibChangeNotify.cs
1 using System;
2 using System.Security;
3 using Microsoft.Win32.SafeHandles;
4
5 namespace System.Net.NetworkInformation
6 {
7     // This class guarantees that any in-progress notifications will be canceled before the AppDomain gets unloaded.
8     // CancelMibChangeNotify2 guarantees that after it returns, the callback will NEVER be called.  It may block
9     // for a small amount of time if the callback is currently in progress, which is fine (and, intentional).
10
11     [SuppressUnmanagedCodeSecurity]
12     internal class SafeCancelMibChangeNotify : SafeHandleZeroOrMinusOneIsInvalid
13     {
14         public SafeCancelMibChangeNotify() : base(true) { }
15
16         protected override bool ReleaseHandle()
17         {
18             uint err = UnsafeNetInfoNativeMethods.CancelMibChangeNotify2(base.handle);
19             base.handle = IntPtr.Zero;
20             return (err == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS);
21         }
22     }
23 }