Environment.FailFast 方法

定義

將訊息寫入 Windows 應用程式事件記錄檔後立即終止處理程序,然後在向 Microsoft 回報錯誤時,包含該訊息並選擇性包含例外狀況資訊。Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and optional exception information in error reporting to Microsoft.

多載

FailFast(String)

將訊息寫入 Windows 應用程式事件記錄檔後立即終止處理序,然後在向 Microsoft 回報錯誤時包含該訊息。Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message in error reporting to Microsoft.

FailFast(String, Exception)

將訊息寫入 Windows 應用程式事件記錄檔後立即終止處理程序,然後在向 Microsoft 回報錯誤時,包含該訊息和例外狀況資訊。Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and exception information in error reporting to Microsoft.

FailFast(String)

將訊息寫入 Windows 應用程式事件記錄檔後立即終止處理序,然後在向 Microsoft 回報錯誤時包含該訊息。Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message in error reporting to Microsoft.

public:
 static void FailFast(System::String ^ message);
[System.Security.SecurityCritical]
public static void FailFast (string message);
static member FailFast : string -> unit
Public Shared Sub FailFast (message As String)

參數

message
String

解釋處理程序結束原因的訊息;如果未提供任何解釋,則為 nullA message that explains why the process was terminated, or null if no explanation is provided.

屬性

範例

下列範例會將記錄專案寫入 Windows 應用程式事件記錄檔,並終止目前的進程。The following example writes a log entry to the Windows Application event log and terminates the current process.

using System;

class Example
{
    public static void Main() 
    {
       string causeOfFailure = "A catastrophic failure has occurred.";

       // 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.");
       }
   }
}
/*
The example produces no output 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.
*/
Module Example
    Public Sub Main()
        Dim causeOfFailure As String = "A catastrophic failure has occurred."
        ' 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.")
        End Try
    End Sub
End Module
'
' The code example displays no output 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.

備註

這個方法會終止進程,而不會執行任何作用中的 try @ no__t-1 @ no__t-2 區塊或完成項。This method terminates a process without running any active try/finally blocks or finalizers.

@No__t-0 方法會將 @no__t 1 字串寫入 Windows 應用程式事件記錄檔、建立應用程式的傾印,然後終止目前的進程。The Environment.FailFast method writes the message string to the Windows Application event log, creates a dump of your application, and then terminates the current process. 在向 Microsoft 回報錯誤時,也會包含 @no__t 0 字串。The message string is also included in error reporting to Microsoft.

如果應用程式的狀態已損毀超過 repair,而執行應用程式的 try @ no__t-3 @ no__t-4 區塊和完成項,則會使用 Environment.FailFast 方法(而不是 Exit 方法)來終止您的應用程式,而使其程式資源受損。Use the Environment.FailFast method instead of the Exit method to terminate your application if the state of your application is damaged beyond repair, and executing your application's try/finally blocks and finalizers will corrupt program resources.

資訊會使用 Windows 錯誤報告向 Microsoft 回報。Information is reported to Microsoft by using Windows Error Reporting. 如需詳細資訊,請參閱 [Windows 錯誤報告:消費者入門 @ no__t-0。For more information, see Windows Error Reporting: Getting Started.

呼叫 Environment.FailFast 方法以終止執行在 Visual Studio 偵錯工具中的應用程式會擲回 ExecutionEngineException,並自動觸發fatalExecutionEngineError managed 偵錯工具(MDA)Calling the Environment.FailFast method to terminate execution of an application running in the Visual Studio debugger throws an ExecutionEngineException and automatically triggers the fatalExecutionEngineError managed debugging assistant (MDA).

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 部分信任或透明的程式碼無法使用這個成員。This member cannot be used by partially trusted or transparent code.

FailFast(String, Exception)

將訊息寫入 Windows 應用程式事件記錄檔後立即終止處理程序,然後在向 Microsoft 回報錯誤時,包含該訊息和例外狀況資訊。Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message and exception information in error reporting to Microsoft.

public:
 static void FailFast(System::String ^ message, Exception ^ exception);
[System.Security.SecurityCritical]
public static void FailFast (string message, Exception exception);
static member FailFast : string * Exception -> unit

參數

message
String

解釋處理程序結束原因的訊息;如果未提供任何解釋,則為 nullA message that explains why the process was terminated, or null if no explanation is provided.

exception
Exception

表示造成終止之錯誤的例外狀況。An exception that represents the error that caused the termination. 這通常是 catch 區塊中的例外狀況。This is typically the exception in a catch block.

屬性

備註

這個方法會終止進程,而不會執行任何作用中的 try @ no__t-1 @ no__t-2 區塊或完成項。This method terminates the process without running any active try/finally blocks or finalizers.

@No__t-0 方法會將 @no__t 1 字串寫入 Windows 應用程式事件記錄檔、建立應用程式的傾印,然後終止目前的進程。The Environment.FailFast method writes the message string to the Windows Application event log, creates a dump of your application, and then terminates the current process.

資訊會使用 Windows 錯誤報告向 Microsoft 回報。Information is reported to Microsoft by using Windows Error Reporting. 如需詳細資訊,請參閱 [Windows 錯誤報告:消費者入門 @ no__t-0。For more information, see Windows Error Reporting: Getting Started. 向 Microsoft 回報錯誤包含 messageexception 資訊,其中提供用來分類錯誤的詳細資料。Error reporting to Microsoft includes message and exception information, which provides details used to classify the error. 雖然不會處理 exception,因為進程已終止,仍然會取得引發例外狀況的內容資訊。Although exception is not handled because the process is terminated, the contextual information that raised the exception is still obtained.

如果 exceptionnull,或如果未擲回 exception,則此方法的運作方式與 FailFast(String) 方法多載相同。If exception is null, or if exception is not thrown, this method operates the same as the FailFast(String) method overload.

如果應用程式的狀態已損毀超過 repair,而執行應用程式的 try @ no__t-3 @ no__t-4 區塊和完成項,則會使用 Environment.FailFast 方法(而不是 Exit 方法)來終止您的應用程式,而使其程式資源受損。Use the Environment.FailFast method instead of the Exit method to terminate your application if the state of your application is damaged beyond repair, and executing your application's try/finally blocks and finalizers will corrupt program resources.

呼叫 Environment.FailFast 方法以終止執行在 Visual Studio 偵錯工具中的應用程式會擲回 ExecutionEngineException,並自動觸發fatalExecutionEngineError managed 偵錯工具(MDA)Calling the Environment.FailFast method to terminate execution of an application running in the Visual Studio debugger throws an ExecutionEngineException and automatically triggers the fatalExecutionEngineError managed debugging assistant (MDA).

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫者。requires full trust for the immediate caller. 部分信任或透明的程式碼無法使用這個成員。This member cannot be used by partially trusted or transparent code.

適用於