mscorlib 2.0.0.0 4.0.0.0 System.Runtime.ConstrainedExecution.CriticalFinalizerObject System.IDisposable

The class is similar to the class, except that implements reference counting. You can use instead of to address performance considerations when you can provide the necessary synchronization more efficiently yourself.

Because the class does not perform reference counting, it does not provide protection from handle recycling security attacks. Because the reference counting algorithm implicitly serializes operations, a certain amount of thread safety is also lost. If you call the or method while an operation that is using the handle is outstanding on another thread, or if you call or from two threads at the same time, the results are non-deterministic. The class still provides the guaranteed critical finalization provided by the class.

Represents a wrapper class for handle resources.

- Constructor
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)
  To be added.

  Initializes a new instance of the class with the specified invalid handle value.

  The value of an invalid handle (usually 0 or -1).
- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  Calling the or method allows the resources to be freed. Unlike the class, this will always happen immediately since there is no reference count to indicate that other threads are using this handle. Therefore, you must employ a synchronization mechanism to ensure it is safe to call the method. Although most classes that use the class do not need to provide a finalizer, this is sometimes necessary (for example, to flush out file buffers or to write some data back into memory). In this case, the class can provide a finalizer that is guaranteed to run before the critical finalizer runs.

  Call the or method when you are finished using the object. The method leaves the object in an unusable state.

  Note Always call or before you release your last reference to the object. Otherwise, the resources it is using will not be freed until the garbage collector calls the object's method.

  Marks the handle for releasing and freeing resources.

- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  Calling the or method allows the resources to be freed. Unlike the class, this will always happen immediately since there is no reference count to indicate that other threads are using this handle. Therefore, you must employ a synchronization mechanism to ensure it is safe to call the method. Although most classes that use the class do not need to provide a finalizer, this is sometimes necessary (for example, to flush out file buffers or to write some data back into memory). In this case, the class can provide a finalizer that is guaranteed to run before the critical finalizer runs.

  Call the or method when you are finished using the object. The method leaves the object in an unusable state.

  Note Always call the or method before you release your last reference to the object. Otherwise, the resources it is using will not be freed until the garbage collector calls the object's method.

  Releases all resources used by the .

- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void ``

  You should never explicitly call the method with the parameter set to false.

  Releases the unmanaged resources used by the class specifying whether to perform a normal dispose operation.

  true for a normal dispose operation; false to finalize the handle.
- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  The method is the destructor for the class. Application code should not call this method directly.

  Frees all resources associated with the handle.

- Field
  2.0.0.0
  4.0.0.0
  System.IntPtr

  Do not expose the handle publicly (that is, outside of the derived class).

  Specifies the handle to be wrapped.

- Property
  2.0.0.0
  4.0.0.0
  get: System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Boolean To be added.

  The method returns a value indicating whether the object's handle is no longer associated with a native resource. This differs from the definition of the property, which computes whether a given handle is always considered invalid. The method returns a true value in the following cases:

  The method was called.

  The method or method was called and there are no references to the object on other threads.

  Gets a value indicating whether the handle is closed.

- Property
  2.0.0.0
  4.0.0.0
  get: System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Boolean To be added.

  Derived classes must implement the property so that the common language runtime can determine whether critical finalization is required. Derived classes must provide an implementation that suits the general type of handle they support (0 or -1 is invalid). These classes can then be further derived for specific safe handle types.

  Unlike the property, which reports whether the object has finished using the underlying handle, the property calculates whether the given handle value is always considered invalid. Therefore, the property always returns the same value for any one handle value.

  When overridden in a derived class, gets a value indicating whether the handle value is invalid.

- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Boolean

  The method is guaranteed to be called only once, provided that you employ proper synchronization mechanisms to ensure that only one call to the or method is made. The method will not be called if the or property is true. Implement this method in your derived classes to execute any code that is required to free the handle. Because one of the functions of is to guarantee prevention of resource leaks, the code in your implementation of must never fail. The garbage collector calls after normal finalizers have been run for objects that were garbage collected at the same time, and guarantees the resources to invoke it and that it will not be interrupted while it is in progress. This method will be prepared as a constrained execution region (CER) at instance construction time (along with all the methods in its statically determinable call graph). Although this prevents thread abort interrupts, you must still be careful not to introduce any fault paths in your overridden method. In particular, apply the attribute to any methods you call from . In most cases this code should be:

  ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)

  Additionally, for simple cleanup (for example, calling the Win32 API CloseHandle on a file handle) you can check the return value for the single platform invoke call. For complex cleanup, you may have a lot of program logic and many method calls, some of which might fail. You must ensure that your program logic has fallback code for each of those cases.

  If the method returns false for any reason, it generates a ReleaseHandleFailed Managed Debugging Assistant.

  When overridden in a derived class, executes the code required to free the handle.

  true if the handle is released successfully; otherwise, in the event of a catastrophic failure, false. In this case, it generates a ReleaseHandleFailed Managed Debugging Assistant.

- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void ``

  Use the method only if you need to support a pre-existing handle (for example, if the handle is returned in a structure) because the .NET Framework COM interop infrastructure does not support marshaling handles in a structure.

  Sets the handle to the specified pre-existing handle.

  The pre-existing handle to use.
- Method
  2.0.0.0
  4.0.0.0
  System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.Success)
  System.Void

  Call the method only when you know that your handle is invalid and you want to mark it as such. Doing so does not change the value of the field; it only marks the handle as invalid. The handle might then contain a potentially stale value. The effect of this call is that no attempt is made to free the resources.

  As with the method, use only if you need to support a pre-existing handle.

  Marks a handle as invalid.