System.Environment.FailFast 方法 (String)

方法描述

向 Windows 的应用程序事件日志写入消息后立即终止进程,然后在发往 Microsoft 的错误报告中加入该消息。

语法定义(C# System.Environment.FailFast 方法 (String) 的用法)

public static void FailFast(
	string message
)

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
message System-String 解释进程终止原因的消息,或者如果未提供解释则返回 null。
返回值 void

提示和注释

此方法终止进程而不需要运行任何活动的 try/finally 块或终结器。

FailFast 方法将 message 字符串写入 Windows 应用程序事件日志,创建应用程序的转储,然后终止当前进程。 message 字符串也包含在报告给 Microsoft 的错误中。

如果应用程序状态为损坏且无法修复,并且执行应用程序的try/finally块和终结器将损坏程序资源,请使用 FailFast 方法而不是 Exit 方法终止应用程序。

System.Environment.FailFast 方法 (String)例子

下面的示例向 Windows Application 事件日志写入日志项并终止当前进程。

// This code example demonstrates the Environment.FailFast() 
// method.

using System;

class Sample 
{
    public static void Main() 
    {
    string causeOfFailure = "A castrophic failure has occured.";

// Assume your application has failed catastrophically and must 
// terminate immediately. The try-finally block is not executed 
// and is included only to demonstrate that instructions within 
// try-catch blocks and finalizers are not performed.

    try 
        {
        Environment.FailFast(causeOfFailure);
        }
    finally
        {
        Console.WriteLine("This finally block will not be executed.");
        }
    }
}

/*
This code example produces the following results:

(No output is produced because the application is terminated. However, 
an entry is made in the Windows Application event log, and the log 
entry contains the text from the causeOfFailure variable.)

*/

异常

异常 异常描述

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。