Export (0) Print
Expand All

RuntimeHelpers Class

Provides a set of static methods and properties that provide support for compilers. This class cannot be inherited.

System.Object
  System.Runtime.CompilerServices.RuntimeHelpers

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

public static class RuntimeHelpers

The RuntimeHelpers type exposes the following members.

  NameDescription
Public propertyStatic memberSupported by the XNA FrameworkOffsetToStringDataGets the offset, in bytes, to the data in the given string.
Top

  NameDescription
Public methodStatic memberEnsureSufficientExecutionStackEnsures that the remaining stack space is large enough to execute the average .NET Framework function.
Public methodStatic memberEquals(Object, Object)Determines whether the specified Object instances are considered equal.
Public methodStatic memberExecuteCodeWithGuaranteedCleanupExecutes code using a Delegate while using another Delegate to execute additional code in case of an exception.
Public methodStatic memberGetHashCode(Object)Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures such as a hash table.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryGetObjectValueBoxes a value type.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryInitializeArrayProvides a fast way to initialize an array from data that is stored in a module.
Public methodStatic memberPrepareConstrainedRegionsDesignates a body of code as a constrained execution region (CER).
Public methodStatic memberPrepareConstrainedRegionsNoOPDesignates a body of code as a constrained execution region (CER) without performing any probing.
Public methodStatic memberPrepareContractedDelegateProvides a way for applications to dynamically prepare AppDomain event delegates.
Public methodStatic memberPrepareDelegateIndicates that the specified delegate should be prepared for inclusion in a constrained execution region (CER).
Public methodStatic memberPrepareMethod(RuntimeMethodHandle)Prepares a method for inclusion in a constrained execution region (CER).
Public methodStatic memberPrepareMethod(RuntimeMethodHandle, RuntimeTypeHandle[])Prepares a method for inclusion in a constrained execution region (CER) with the specified instantiation.
Public methodStatic memberProbeForSufficientStackProbes for a certain amount of stack space to ensure that a stack overflow cannot happen within a subsequent block of code (assuming that your code uses only a finite and moderate amount of stack space). We recommend that you use a constrained execution region (CER) instead of this method.
Public methodStatic memberRunClassConstructorRuns a specified class constructor method.
Public methodStatic memberRunModuleConstructorRuns a specified module constructor method.
Top

The following example shows how to reliably set handles by using the PrepareConstrainedRegions method. To reliably set a handle to a specified pre-existing handle, you must ensure that the allocation of the native handle and the subsequent recording of that handle within a SafeHandle object is atomic. Any failure between these operations (such as a thread abort or out-of-memory exception) will result in the native handle being leaked. You can use the PrepareConstrainedRegions method to make sure that the handle is not leaked.


    [StructLayout(LayoutKind.Sequential)]
    struct MyStruct
    {
        public IntPtr m_outputHandle;
    }

    sealed class MySafeHandle : SafeHandle
    {
        // Called by P/Invoke when returning SafeHandles
        public MySafeHandle()
            : base(IntPtr.Zero, true)
        {
        }

        public MySafeHandle AllocateHandle()
        {
            // Allocate SafeHandle first to avoid failure later.
            MySafeHandle sh = new MySafeHandle();

            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                MyStruct myStruct = new MyStruct();
                NativeAllocateHandle(ref myStruct);
                sh.SetHandle(myStruct.m_outputHandle);
            }

            return sh;
        }



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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

Community Additions

ADD
Show:
© 2014 Microsoft