Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force exit application in C#?

I have a multi threaded C# application and it has reader writer lock,but it gives a timeout exception on some computers(not being able to acquire a lock in time) and I need to forcefully close all threads. how do I do it without getting any extra exceptions?

like image 759
armin Avatar asked Nov 01 '11 18:11

armin


People also ask

How do I force a program to end in C?

The exit() is a function and not a command. Unlike the return statement, it will cause a program to stop execution even in a function. And the exit() function can also return a value when executed, like the return statement. So the C family has three ways to end the program: exit(), return, and final closing brace.

Is there an exit function in C?

C # in TeluguThe exit () function is used to break out of a loop. This function causes an immediate termination of the entire program done by the operation system. void exit (int code);

What is the exit code in C?

The purpose of the exit() function is to terminate the execution of a program. The “return 0”(or EXIT_SUCCESS) implies that the code has executed successfully without any error. Exit codes other than “0”(or EXIT_FAILURE) indicate the presence of an error in the code.

Why exit is not working in C?

Under any version of the language, exit requires a single argument of type int . Passing 0 or EXIT_SUCCESS (a macro defined in <stdlib. h> causes the program to terminate and pass a status to the environment indicating success. Passing EXIT_FAILURE causes the program to terminate with a status indicating failure.


1 Answers

I think the best solution to force application exit is to use the following line of code:

Environment.Exit(0) 

Environment.FailFast() ends up with a runtime exception.

like image 104
luke Avatar answered Sep 20 '22 14:09

luke