Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
FailFast Method (String)
Collapse the table of content
Expand the table of content

Environment.FailFast Method (String)

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
Assemblies:   mscorlib (in mscorlib.dll)
  System.Runtime.Extensions (in System.Runtime.Extensions.dll)

public static void FailFast(
	string message
)

Parameters

message
Type: System.String

A message that explains why the process was terminated, or null if no explanation is provided.

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.

Information is reported to Microsoft by using Windows Error Reporting. For more information, see Windows Error Reporting: Getting Started.

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 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.");
       }
   }
}
/*
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.
*/

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Show:
© 2015 Microsoft