title: C# Windows Form Takes Forever to Load
body: <p>I'm developing a Windows Form launcher / update / splash screen application to be used on a Windows 7 Panasonic Toughbook (Tablet) in C#. The launcher works fine on my desktop and one of my Toughbooks... However, testing on the "real environment" device takes 20+ seconds to even show the form after the first launch. (Once the form is shown, it goes fast, the way the app is suppose to work.) The first launch on the device after installation is quick, but after the first launch, it takes a long time.</p>
  
  <p>I'm not really sure how to go about even testing this, since this is on a device that can't be connected to via USB or put on our network. It doesn't seem to matter if the application opens files or not. In fact in most cases, the app just opens up, see's that it's too soon to check for another update, launches the main app, and kills itself.</p>
  
  <p>The current process looks like this:</p>
  
  <p>constructor:</p>
  
  <pre><code>public MyConstructor() { InitializeComponent(); }
  </code></pre>
  
  <p>Form Load:</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
  {
      if (!isLoaded)
      {
          System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap("parentApplication.exe.config"); //Path to your config file
          System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
          log4net.Config.XmlConfigurator.Configure();
          WebRequest.url = configManager.AppSettings.Settings["SURL"].Value;
  
          // Set a timer to run the update process momentarily to allow the UI thread to update and display. (UI must be idle to run Timer)
          updateTimer = new System.Timers.Timer(1000);
          updateTimer.Elapsed += new ElapsedEventHandler(beginUpdate);
          updateTimer.Enabled = true;
          isLoaded = true;
      }
  }
  </code></pre>
  
  <p>Update Process</p>
  
  <pre><code>private void beginUpdate(Object sender, EventArgs e)
  {
      // If any of this fails, we still want to launch the main application. 
      try
      {
              // Prevent the timer from doing anything else.
              updateTimer.Enabled = false;
  
              string version = "0";
              try
              {
                  Version v = AssemblyName.GetAssemblyName("ParentApplication.exe").Version;
                  version = v.ToString();
              }
              catch
              {
                  version = "0";
              }
  
              updateProgress(5);
  
              DateTime buffer = DateTime.Now.AddMinutes(-5);
              DateTime last = Convert.ToDateTime(configManager.AppSettings.Settings[lastCheck].Value);
              int comp = DateTime.Compare(buffer, last);
  
              if (comp &lt; 0)
              {
                  // Begin update process
                  updateApplication(version);
              }
  
              updateProgress(100);
  
              System.Threading.Thread.Sleep(1000);
          }
          catch (Exception er)
          {
              logger.Error("Error in update application.", er);
          }
  
          // The updater can't update itself. Launch the external application
          // to handle the updating of the updater. This application also launches
          // the main executable.
          Process sync = new Process();
          sync.StartInfo.UseShellExecute = false;
          sync.StartInfo.FileName = "FinishUpdate.exe";
          sync.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
          sync.StartInfo.Verb = "runas";
          sync.Start();
          Application.Exit();
  }
  </code></pre>