Connecting Tech Pros Worldwide Forums | Help | Site Map

ObjectDisposedException On Application.Run()

Newbie
 
Join Date: Oct 2008
Posts: 6
#1: Oct 25 '08
Hello,
I have been trying to get my application to try and load config in from an xml file, however i want it to bring up a config window if it fails to load the configuration. However when i close the form used in Program.cs/Application.Run(new Form()) and try to open the config form the program crashes because the Application.Run() loop is still looking for the main form, i have tried a few things like Application.Run() without arguments etc but it just makes no forms show up.

Here are some code examples:
Expand|Select|Wrap|Line Numbers
  1.  
  2. public partial class StartScreen : Form     
  3. {
  4.          public StartScreen()
  5.          {
  6.             InitializeComponent();
  7.             ClientCare_Session.StartWindowInstance = this;
  8.             if (!ClientCare_Session.Started)
  9.                  ClientCare_Session.StartSession();
  10.          }
  11.           private void StartScreen_Load(object sender, EventArgs e)
  12.          {
  13.          }
  14.      }
  15.  
Expand|Select|Wrap|Line Numbers
  1.  public static void StartSession() 
  2.         { 
  3.             Started = true; 
  4.             LoadConfig(); 
  5.             ClientCare_Database.Install(); 
  6.         }
  7.         public static void LoadConfig()
  8.         {
  9.             try
  10.             {
  11.                 XmlDocument doc = new XmlDocument(); 
  12.                 XmlNodeReader reader; 
  13.                 XmlNode node; 
  14.                 doc.Load(String.Format("{0}\\{1}", ClientCare_Session.AppPath, ConfigFile)); 
  15.                 node = doc.DocumentElement.SelectSingleNode("MySQL"); 
  16.                 reader = new XmlNodeReader(node); 
  17.                 while (reader.Read())
  18.                 {
  19.                     switch (reader.Name)
  20.                     {
  21.                         case "Username": { break; }
  22.                     }
  23.                 }
  24.             }
  25.             catch (Exception)
  26.             {
  27.                 ClientCare_Config form = new ClientCare_Config(true); form.Show(); StartWindowInstance.Hide();
  28.             }
  29.         }
thank you for any help

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Oct 27 '08

re: ObjectDisposedException On Application.Run()


Don't load the config from withen the form object.
Load it before hand. It it fails, popup your config window, if it succeeds pop open your regular window?
Reply