The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SafeHandle Class

For apps that target Windows Phone OS 7.0 and 7.1, do not use any members of this type in your app. If you do, your code will throw a MethodAccessException. This type is security-critical, which restricts it to internal use by the .NET Framework for Windows Phone class library.

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Represents a wrapper class for operating system handles. This class must be inherited.

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

public abstract class SafeHandle : IDisposable

The SafeHandle type exposes the following members.

Protected methodSafeHandle()Initializes a new instance of the SafeHandle class using system defaults.
Protected methodSafeHandle(IntPtr, Boolean)Initializes a new instance of the SafeHandle class with the specified invalid handle value.

Public propertyIsClosedGets a value indicating whether the handle is closed.
Public propertyIsInvalidWhen overridden in a derived class, gets a value indicating whether the handle value is invalid.

Public methodCloseSecurity Critical. Marks the handle for releasing and freeing resources.
Public methodDangerousAddRefSecurity Critical. Manually increments the reference counter on SafeHandle instances.
Public methodDangerousGetHandleReturns the value of the handle field.
Public methodDangerousReleaseSecurity Critical. Manually decrements the reference counter on a SafeHandle instance.
Public methodDispose()Releases all resources used by the SafeHandle class.
Protected methodDispose(Boolean)Security Critical. Releases the unmanaged resources used by the SafeHandle class specifying whether to perform a normal dispose operation.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodReleaseHandleWhen overridden in a derived class, executes the code required to free the handle.
Protected methodSetHandleSets the handle to the specified pre-existing handle.
Public methodSetHandleAsInvalidSecurity Critical. Marks a handle as no longer used.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

Protected fieldhandleSpecifies the handle to be wrapped.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.