In order to show a first run dialog (a window that appears before the main application starts if certain conditions are met) I have decided to modify the Main method and do this:

        static void Main()

            if (Properties.Settings.Default.FirstRun)
                Application.Run(new RunOnce());

            Application.Run(new Main());

Is this a bad idea? It works, and with a bit of additional logic I can prevent the main application from even opening should the user cancel out of the first run dialog.


I'm guessing you want a form that runs before the main form, but you still want to defer the application thread to the main forum? There are a few ways to do that; one of the simpler ones can be seen in a service configuration utility I wrote that looks something like this:

public static void Main(string[] args) {

private static void RunApplication(string[] args) {
    Trace.AutoFlush = true;
    Trace.Listeners.Add(new TextWriterTraceListener(TraceFile, "Listener_" + ProductShortName + ".Config"));


    AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => {
        string msg = (e.ExceptionObject as Exception).ToString();
        string logMsg = "Fatal Error: Unhandled exception [" + msg + "]";
        string usrMsg = "An error was detected at load time. Refer to the trace log for details";


        if (Application.MessageLoop)

    var form = new ServiceConfig();

    if (!form.Login()) {
        Utility.FatalBox("Login failed.");
    } else {

The main form is ServiceConfig, and it has a method that opens a modal dialog for logging in to an external application. All of this is done before the Application.Run(), so the login dialog appears first and if it fails or is canceled the main form won't show.

Kind of. What I am after is a form that tests a pre-defined SQL connection string, if the connection passes then a setting is set to true and the form will not be opened in the future so long as the connection still works. If, in the future, the connection fails, the setting is reset to false. If the false setting is found, the RunOnce dialog appears asking the user to verify the connection information and to re-test the connection.

I kind of need one application to open, adjust the connection string in the settings and then start the main application with those new settings.

Since the connection string is stored in the application settings file and has an application scope, not user scope, I can't edit the string without restarting the application. I was hoping this would fix that problem, but it actually doesn't seem to and I found a way to adjust the setting and restart the application in a different manner.

Thank you for the code example!