예제 #1
0
 /// <summary><para>
 /// This function initializes the give RenderForm instance,
 /// runs its main execution loop, and properly shuts it down.
 /// </para><para>
 /// It also properly disposes the Render Form and Splash Form when finished.
 /// </para></summary>
 /// <param name="args">The command line arguments from the application's main entry point.</param>
 /// <param name="mainForm">The main form of the application.</param>
 /// <param name="splash">The splash form displayed while the main form is initializing.</param>
 /// <returns>1 if a problem was encountered, 0 otherwise.</returns>
 public static int MainLoop(string[] args, RenderForm mainForm, ISplashForm splash)
 {
     if (mainForm == null)
     {
         return(1);
     }
     SetDefaultAppDomain(AppDomain.CurrentDomain);
     if (splash != null)
     {
         splash.Show();
         splash.Update();
     }
     using (mainForm)
     {
         if (!mainForm.Init(splash))
         {
             if (splash != null)
             {
                 splash.Close();
                 splash.Dispose();
             }
             mainForm.Shutdown(true);
             return(1);
         }
         mainForm.IsRunning = true;
         bool keepRunning = true;
         keepRunning        = mainForm.ProcessCommandLineArgs(args, keepRunning);
         mainForm.IsRunning = keepRunning;
         if (mainForm.IsRunning)
         {
             if (splash != null)
             {
                 splash.Close();
                 splash.Dispose();
             }
             mainForm.Show();
         }
         while (mainForm.IsRunning)
         {
             Application.DoEvents();
             mainForm.UpdateAndDraw();
         }
         mainForm.Shutdown(false);
     }
     return(0);
 }
예제 #2
0
 /// <summary><para>
 /// This function initializes the give RenderForm instance,
 /// runs its main execution loop, and properly shuts it down.
 /// </para><para>
 /// It traps and displays any errors that occur.
 /// </para><para>
 /// It also properly disposes the Render Form and Splash Form when finished.
 /// </para></summary>
 /// <param name="args">The command line arguments from the application's main entry point.</param>
 /// <param name="mainForm">The main form of the application.</param>
 /// <param name="splash">The splash form displayed while the main form is initializing.</param>
 /// <returns>1 if a problem was encountered, 0 otherwise.</returns>
 public static int MainLoopSafe(string[] args, RenderForm mainForm, ISplashForm splash)
 {
     if (mainForm == null)
     {
         return(1);
     }
     SetDefaultAppDomain(AppDomain.CurrentDomain);
     if (splash != null)
     {
         splash.Show();
         splash.Update();
     }
     using (mainForm)
     {
         try
         {
             if (!mainForm.Init(splash))
             {
                 if (splash != null)
                 {
                     splash.Close();
                     splash.Dispose();
                 }
                 mainForm.Shutdown(true);
                 return(1);
             }
             mainForm.IsRunning = true;
             bool keepRunning = true;
             keepRunning        = mainForm.ProcessCommandLineArgs(args, keepRunning);
             mainForm.IsRunning = keepRunning;
             if (mainForm.IsRunning)
             {
                 if (splash != null)
                 {
                     splash.Close();
                     splash.Dispose();
                 }
                 mainForm.Show();
             }
             while (mainForm.IsRunning)
             {
                 Application.DoEvents();
                 mainForm.UpdateAndDraw();
             }
         }
         catch (Exception ex1)
         {
             try
             {
                 // Display Crashed + Exception
                 ExceptionHelper.ShowException(ex1, "Application Crashed");
                 mainForm.Shutdown(true);
             }
             catch (Exception ex2)
             {
                 // Display Shutdown Failed + Exception
                 ExceptionHelper.ShowException(ex2, "Application Shutdown Failed");
             }
             return(1);
         }
         try
         {
             mainForm.Shutdown(false);
         }
         catch (Exception ex3)
         {
             // Display Shutdown Failed + Exception
             ExceptionHelper.ShowException(ex3, "Application Shutdown Failed");
             return(1);
         }
     }
     return(0);
 }