Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Application.Restart bad?

I've got a .Net windows form application where a lot of variables are initialized in the Main_Load event and I have a situation where I want my DB re-queried and all vars set to null and re-initialized (basically the form 100% reloaded from the start), but I wrote my Main-Load in such a way (my fault) that it's not that easy to do...

I know I could get exactly what I want by simply calling Application.Restart and it does the trick beautifully, but I'm not sure if this is good programming practice or considered really bad.

Are there any problems that I'm likely to run into by using Application.Restart in this context?

like image 810
John Bustos Avatar asked Oct 19 '12 19:10

John Bustos


2 Answers

Not friendly to debug, but there's nothing really wrong with it. It is the exact same as terminating the app and starting it again.

You can avoid it by simply creating a new instance of your main form and closing the old one. That however does require you to prevent the program from exiting. Code is here.

like image 148
Hans Passant Avatar answered Oct 22 '22 01:10

Hans Passant


It's not that the method doesn't work; rather, many times programmers forget that they've put something in their code that would stop the application from automatically shutting down, or starting up.

Please follow this Thread

You can also do the job with

 System.Diagnostics.Process.Start(Application.ExecutablePath);
 Application.Exit();
like image 22
Rahul Tripathi Avatar answered Oct 22 '22 01:10

Rahul Tripathi