You would want to call Application.Exit(); rather which would terminates all message loops and closes all windows, giving your forms the possibility to execute their cleanup code. See Application.Exit for more information. Quoting from documentation
Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.