c sharp

C# Environment.HasShutdownStarted

HasShutdownStarted Property in Environment class is used to check if the current application is unloaded or not.

If the Common Language Runtime (CLR) is shutting down, it will check and return true. Otherwise, false is returned.

If you are using this property in .NET Framework, it runs the finalizers on all objects if the applications starts unloading. Each object has a finalizer method.

If the finalizer thread is started, it returns true. If the finalizer thread is not started, it will return false.

Syntax:

bool Environment.HasShutdownStarted

 
Return:

Boolean value True is returned if the application starts shutting down, otherwise False is returned.

Example 1:

Here, we will create the application and check if it is unloaded or not.

using System;
class Linuxhint {
    //let's implement HasShutdownStarted property inside main method
  static public  void Main() {
      //check for unloading
    Console.WriteLine("Does the Application start shutting down? : "+Environment.HasShutdownStarted  );
  }
}

 
Output:


The Application did not start shutting down.

Explanation:

Line 4:

We are implementing our property inside the Main method.

Line 6:
 

Console.WriteLine("Does the Application start shutting down? : "+Environment.HasShutdownStarted  );

 
Here, we are directly using the HasShutdownStarted property to check whether the application is unloaded or not.

Example 2:

Here, we will create the application and check if it is unloaded or not by storing the result in one Boolean variable.

using System;
class Linuxhint {
    //let's implement HasShutdownStarted property inside main method
  static public  void Main() {
      //check for unloading
      bool check=Environment.HasShutdownStarted;
    Console.WriteLine("Does the Application start shutting down? : "+check);
  }
}

 
Output:


The Application did not start shutting down.

Explanation:

Line 6:

bool check=Environment.HasShutdownStarted;

 

We created a Boolean variable check and store the status of the application in it.

Line 7:

Console.WriteLine("Does the Application start shutting down? : "+check);

 
Finally, we are displaying the result with the Console.WriteLine() method.

Conclusion

With this article, we came to know that using Environment.HasShutdownStarted property will return a Boolean value True if the application starts shutting down. Otherwise, False is returned. If the finalizer thread in .NET Framework is started, it returns true. If the finalizer thread is not started, it will return false.

About the author

Gottumukkala Sravan Kumar

B tech-hon's in Information Technology; Known programming languages - Python, R , PHP MySQL; Published 500+ articles on computer science domain