Consistency 枚举
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
The Constrained Execution Region (CER) feature is not supported.
指定可靠性协定。
public enum class Consistency
C#
[System.Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId="SYSLIB0004", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum Consistency
C#
public enum Consistency
C#
[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
- 继承
- 属性
名称 | 值 | 说明 |
---|---|---|
MayCorruptAppDomain | 1 | 在遇到异常情况时,公共语言运行时 (CLR) 对当前应用程序域中的状态一致性不做任何保证。 |
MayCorruptInstance | 2 | 在遇到异常情况时,此方法保证将状态损坏限制到当前实例。 |
MayCorruptProcess | 0 | 在遇到异常情况时,CLR 对状态一致性不做任何保证;即这种情况可能损坏进程。 |
WillNotCorruptState | 3 | 在遇到异常情况时,此方法保证不损坏状态。 (不保证此方法永远不会失效;但确实可以保证此类故障将永远不损坏状态。) |
下面的代码示例演示了在为方法指定受约束的执行区域时如何使用 Consistency 枚举。 此代码示例是为 构造函数提供的更大示例的 ReliabilityContractAttribute 一部分。
C#
[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 以指定给定方法的可靠性保证。
产品 | 版本 (已过时) |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1 (5, 6, 7, 8, 9) |
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |