Επεξεργασία

Κοινή χρήση μέσω


Cer Enum

Definition

Caution

The Constrained Execution Region (CER) feature is not supported.

Specifies a method's behavior when called within a constrained execution region.

public enum class Cer
[System.Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId="SYSLIB0004", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum Cer
public enum Cer
[System.Serializable]
public enum Cer
[<System.Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId="SYSLIB0004", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type Cer = 
type Cer = 
[<System.Serializable>]
type Cer = 
Public Enum Cer
Inheritance
Attributes

Fields

Name Value Description
None 0

The method, type, or assembly has no concept of a CER. It does not take advantage of CER guarantees.

MayFail 1

In the face of exceptional conditions, the method might fail. In this case, the method will report back to the calling method whether it succeeded or failed. The method must have a CER around the method body to ensure that it can report the return value.

Success 2

In the face of exceptional conditions, the method is guaranteed to succeed. You should always construct a CER around the method that is called, even when it is called from within a non-CER region. A method is successful if it accomplishes what is intended. For example, marking Count with ReliabilityContractAttribute(Cer.Success) implies that when it is run under a CER, it always returns a count of the number of elements in the ArrayList and it can never leave the internal fields in an undetermined state.

Examples

The following code example demonstrates the use of the Cer enumeration when specifying a constrained execution region for a method. This code example is part of a larger example provided for the ReliabilityContractAttribute constructor.

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
[MethodImpl(MethodImplOptions.NoInlining)]
void StackDepth2()
{
    try
    {
        consistentLevel2 = false;
        if (depth == 2)
            Thread.Sleep(-1);
        StackDepth3();
    }
    finally
    {
        consistentLevel2 = true;
    }
}
<ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)>
<MethodImpl(MethodImplOptions.NoInlining)>
Sub StackDepth2()
   Try
      consistentLevel2 = False
      If depth = 2 Then Thread.Sleep(-1)
      StackDepth3()
   Finally
      consistentLevel2 = True
   End Try
End Sub

Remarks

The Cer enumeration specifies the behavior of a method, type, or assembly within a constrained execution region (CER). Use one of the three available values to indicate that the entity will succeed, has no knowledge of a CER, or might (deterministically) be able to report success or failure.

A CER provides guarantees that the region of code will execute uninterrupted even if an asynchronous exception such as an aborted thread out-of-memory exception, or stack overflow is raised.

However, the Cer.None enumeration value indicates that the method, type, or assembly has no concept of a CER. It does not take advantage of CER guarantees. This implies the following:

  • In the face of exceptional conditions the method might fail.

  • The method might or might not report that it failed (it is non-deterministic).

  • The method is not written with CERs in mind (which is the most likely scenario).

If a method, type, or assembly is not explicitly marked to succeed, it is implicitly marked as Cer.None.

Applies to

See also