user4671342
user4671342

Reputation:

Showing form when main form gets closed

I have tried around with threads a little bit but I can't figure out the right way to get what I want (because I'm not very familiar with threads). I have a "Sign out" button in my main form. When clicked then the Form shuts completely down and restarts (Application.Restart()). Now I wanted another form pop up when the main form gets closed (Just a label with "Loging out - Please wait"). When the main form opens then this "Log out form" should disappear. I know I should make the Sign out form as foreground thread but how do I call the Form.Open() method with the thread and how I can get it closed when the main form starts?

Upvotes: 0

Views: 95

Answers (1)

Gargo
Gargo

Reputation: 711

Try to show the second form in the FormClosing event of the main form.

When the main form closes it most certainly "shuts down" the message loop of the application making it impossible to spawn any new window or closing any window that is already open.

Edit: As of the comments: Showing the logout form from the process that is about to Restart until the new process has been started successfully will not be possible because the old process will be shut down and therefore any open form it shows.

Possible solutions:

  • Write a program with the solely purpose of showing the logout form and start that before restarting the application. After the Application has startet again search the process of the logout form and stop/kill it.
  • Avoid to have to restart your application completely

Upvotes: 1

Related Questions