Restart Application (exe) Effectively (VB.NET)

This applies to MS .NET programming, MS Windows platform.

Assuming that the application process is running as a non Windows Service. It is a normal exe process.

Invoking 'Application.Restart' doesn't work all the time.

Instead of trying to self terminate a running instance and start a new one thereafter, I found that it is must more efficient if we can start a new instance and using the new instance to detect for previous running instance and kill the previous instance.

Therefore, whenever an instance of the application is starting up, implement a check if existing application is already running. If it does, kill the one that is currently running and allow the new one to continue running. This will restart for sure!

Make use of 'System.Diagnostics.Process' class to check for previous running instance where the idea is the process name (for previous and current running instance) is always the name.

The process name is the name of the application installed; which is the 'Assembly Name' which the application is being built. Make use of 'System.Diagnostics.Process.ProcessName' for this purpose.

One can also make use of 'System.Diagnostics.ProcessStartInfo' class to pass command-line arguments to the newly invoked instance and to make use of 'System.Environment.GetCommandLineArgs()' to retrieve the arguments from the newly launched instance.