What triggers the C# FormClosed event?

795 Views Asked by At

I have an application that connects to an API. The API needs a logout function to be called when work is finished so that its system works properly. I have a function that connects to this API, does some work, and then logs out and it works correctly. The problem is when the program crashes, or I need to close it during work. I have added a call to the logout function in the FormClosing event in my MDI parent form. Will this work for all cases of closing the program?

To be more specific - I know, that clicking on the red X button will trigger this event. But will closing the program from the Windows' Task Manager also trigger it? And will stopping the program from Visual Studio (during development, when it was also run from Visual Studio) also trigger it?

1

There are 1 best solutions below

7
TK-421 On BEST ANSWER
  • It is triggered when the user closes the program.
  • It is triggered when task manager closes the program, but only some fragment of the code in FormClosing will execute, rest will be also killed
  • It is not triggered when Visual Studio stops the program.
  • It is not triggered when the power to a computer is cut off.