Consistency 枚举

定义

注意

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

指定可靠性协定。

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

字段

MayCorruptAppDomain 1

在遇到异常情况时,公共语言运行时 (CLR) 对当前应用程序域中的状态一致性不做任何保证。

MayCorruptInstance 2

在遇到异常情况时,此方法保证将状态损坏限制到当前实例。

MayCorruptProcess 0

在遇到异常情况时,CLR 对状态一致性不做任何保证;即这种情况可能损坏进程。

WillNotCorruptState 3

在遇到异常情况时,此方法保证不损坏状态。 (不保证此方法永远不会失效;但确实可以保证此类故障将永远不损坏状态。)

示例

下面的代码示例演示了在为方法指定受约束的执行区域时如何使用 Consistency 枚举。 此代码示例是为 构造函数提供的更大示例的 ReliabilityContractAttribute 一部分。

[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

注解

枚举 Consistency 用作 属性的参数, ReliabilityContractAttribute 以指定给定方法的可靠性保证。

适用于

另请参阅