Loading data after form loads

  • Thread starter Thread starter Sean Patterson
  • Start date Start date
S

Sean Patterson

Greets all,

I have a little scan gun app that loads a bunch of text files into some
data tables for reference. Currently, I have the loading method occur on
the MyBase.Load event within the app.

Since there is a lot of processing going on, typically I click the
executable on the device, the wait cursor is displayed, and I have this
odd looking screen until the files load.

I was wondering if there is a way to run the method after all of the GUI
stuff loads, so that way I can update a status label and make the
loading a little prettier.

Thanks in advance for any insight you may have!
 
In the load event just before you start your lengthy operation, add
Application.DoEvents();
If you want to update progress, also add the above after every update.
Having said that I need to point out that this kind of things is better done
in a background worker thread.
 
as Alex suggested the long operations is better to implement as
background process. Below is a code snippet how it could be done:

TestForm()
{ System.Threading.ThreadPool.QueueUserWorkItem(
new System.Threading.WaitCallback(Run));
}

void SafeRun(object sender, EventArgs e)
{
// here could be updating progress bar
}

void Run(object o)
{
bool completed = false;
while(!completed)
{
//long processing iteration
this.Invoke(new EventHandler(SafeRun));
}
}
 
Thanks to all three of you for the heads up! I'll DEFINITELY be getting
that thread action going! Hope you all had a happy holiday!

- Sean
 
Back
Top