Domanda

I am looking for the console application equivalent of Application.Restart() but cannot seem to find a way to do this.

It has been suggested by others to simply call my Sub Main with Args when I need to restart. However the reason I need the functionality to physically restart the application is because the first thing I do is check for updates and install them if they any are availible.

The update technique itself works perfectly, the system installs new updates but changes do not take effect until next time the application runs obviously.

As the application is run from a batch file as a scheduled task only once a week any updates I release would not take effect for two weeks!

I had the same problem with a windows forms application however the ability to call Application.Restart allows changes to take place imediately. Can the same be achieved when creating a console application?

È stato utile?

Soluzione

2 Possibilities i can think of.

First one start another instance of the application and close the current one using something like

System.Diagnostics.Process.Start(ProcessStartInfo startInfo)

and

Environment.Exit(int exitCode)

second if it's not possible to run 2 instances at the same time for some reasons u can create another application that gets started by the batch. Make it run your application and let it get an info if the updating process is done so it can first close the current application and then run another one

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top