[c#] How do I restart my C# WinForm Application?

Take for instance an application that:

  1. While application is not registered; (upon start) the application should prompt the user to register the application and create a login account.

  2. Once registration is submitted and login credentials are created; the application should restart, check for registration and prompt the user to login with the inserted credentials (so the user can access to all the application features).

Problem: By building and launching the application from Visual Studio; any of the 4 alternatives bellow will fail to accomplish the tasks required.

/*
 * Note(s):
 * Take into consideration that the lines bellow don't represent a code block.
 * They are just a representation of possibilities,
 * that can be used to restart the application.
 */

Application.Restart();
Application.Exit();
Environment.Exit(int errorCode);
Process.GetCurrentProcess().Kill();

What happens is: After creating the Registration, Login and calling Application.Restart(); the application will (strangely) reopen the Registration Form and skip data in a Database (even though the resource is set to "Copy if Newer").

Solution: Batch Building the application was (for me) a proof that any of the lines above were actually working as expected. Just not when building and running the application with Visual Studio.

In first place I'd try batch building the application; run it outside Visual Studio and check if Application.Restart() actually works as expected.

Also Check further Info regarding this thread subject: How do I restart my C# WinForm Application?