简体   繁体   中英

My Application.Restart Doesn't Complete?

My project requires a restart if the user changes the settings before the settings will take effect. I have created a DialogResult prompt that asks the user if they want to restart the program. I call a MessageBox which returns a Yes/No and if you click "no" it behaves appropriately and doesn't close the program. If you choose "yes" the application closes... and that's it, no restart. I do have some close validation going on which I've read can cause issues, but I was under the impression that was issues with the program closing, not restarting? What might cause the application to not restart? Is there more to the method than just calling it that I need to be doing?

I attempt to restart the application calling the method:

Application.Restart();

As to whether I use threads, I am not consciously using threads cause I don't really know what that means to be honest.

Generally when you use this method, your app will restart.

It is ordinarily a routine action, but I saw in your question that you have some validation logic running when the app is closed. Thus, I'm about 90% sure that this error occurred because some of those validations failed. Post the validation code, and someone can help you debug the problem.

So thanks to the link from above I found a recommendation on a different thread that was a great workaround to simply using the Application.Restart() method.

System.Diagnostics.Process.Start(Application.ExecutablePath);
Application.Exit();

It allows my program to restart very effectively in spite of my closing validation. This would probably still be an issue if I did any closing validation related to the Application.Exit call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM