Where should I read the database

MagnusVS

Member
Joined
Jun 29, 2006
Messages
10
Programming Experience
1-3
Hi.
I have a project where I load the database (several SQL expressions from several tables) in the "Load" event in the main window. When i debug my program, it takes some time before the main window appears because it's loading the database. Is it a way that I can make the main window appear first, and then read the database (so I can give a message to the user about what's happening)?
 
You could create a worker thread to do the work in the background for you. Or new to Vb.net the background worker.

If you are accessing controls from the worker thread you must test the controls invokeRequired property to make sure you are making a safe thread call. Better yet check out Jimcilhinney's example he gave me on this thread. http://www.vbdotnetforums.com/showthread.php?p=44443

BTW, how much data are you loading at the start of your application?
 
Thanks!
I'm loading data from 3 tables in my database. Not very large amounts of data, but I'm interested to find out how to solve the problem in this and in future applications. So I'll check out that link!
Thanks again:)
 
After reading your post again it sounds like you don't really need the form to be active and useable while the data is loading. You could simply just display a splash screen while the data is loading.
 
Yes i guess i can. But the problem is that to make the splash screen appear, doesn't the startup form (the main window) have to appear first so that the splash can be shown from that? Or can i open the splash screen first, and read the database from that?
 
Something like this would work.
VB.NET:
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] Form1[/SIZE]
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Load[/SIZE]
[SIZE=2][/SIZE] 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] frmSplash [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SplashScreen1[/SIZE]
[SIZE=2]frmSplash.Show()[/SIZE]
[SIZE=2]frmSplash.Update()[/SIZE]
[SIZE=2]'Load your data here[/SIZE]
[SIZE=2]frmSplash.Close()[/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]

You can also start your app in a module or class.
 
Back
Top