Environment.FailFast Method (String)
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Immediately terminates a process after writing a message to the Windows Application event log, and then includes the message in error reporting to Microsoft.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
This method terminates a process without running any active try/finally blocks or finalizers.
The FailFast method writes the message string to the Windows Application event log, creates a dump of your application, and then terminates the current process. The message string is also included in error reporting to Microsoft.
Use the 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.
The following example writes a log entry to the Windows Application event log and terminates the current process.
// 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.) */
-
SecurityCriticalAttribute
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.