Results 1 to 3 of 3

Thread: Form_Load event

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    London
    Posts
    63

    Form_Load event

    When opening a form, I am loading data into a few combo boxes from an Oracle database.

    I make a call to a class that load the data from the Form_Load event.

    The form hangs and is not fully drawn until my data fetching is complete.

    I used to have this problem in VB but I used the .Show method then, at the begining of the Form_Load event to show the form before getting data from the database which solved that.

    I tried this in C# but it doesn't seem to work.

    Any idea's on how I can show the form fully and have the data load whilst it is shown.

  2. #2
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    You can load the data in a seperate thread.

    Code:
    using System.Threading;
    
    // ....
    class myForm : Form
    {
         public void LoadDatabase()
         {
              // ... do stuff
         }
    
         public void myForm_Load()
         {
              Thread t = new Thread(new ThreadStart(LoadDatabase) );
              t.Start();
         }
    
    }
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    also, if u wanto to create controls in the form in that method, u cant as u have to create another method that does that job and u must call it as this.BeginInvoke(<delegate pointing to the method>, <args if any>); otherwise u'll get an error in the threads
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width