PandaNL
PandaNL

Reputation: 848

Form load interface

In my form_load I have a mysql connection that loads data in a datagrid, when starting my application it will first try to load the mysql database and after its done it will load the form/interface with all the controls.

This leaves the user the impression nothing is happening, how can I first load the form/interface with all the controls and then my mysql database?

Upvotes: 0

Views: 144

Answers (5)

T.S.
T.S.

Reputation: 19330

I would say, 3 approaches

1 - Separate Splash screen

2 - On-Form "splash screen" - first thing you do on form.load, is Me.Show(), then show a message, something like "Please wait while data is loaded". Progress can be shown to users as well using Application.DoEvents which will refresh your screen.

3 - Background worker thread. Using it, you can actually give user progress updates. That will leave your form completely responsive. http://msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx

Upvotes: 1

Icemanind
Icemanind

Reputation: 48686

There are two ways to approach this situation. You need to pick the approach that best suits your needs.

Approach 1: Create a splash screen. A splash screen is a small window that opens up and usually had product info and a message like "Initializing...". You can see this in a lot of applications, such as Microsoft Office. You can see how to make one by looking at this article.

Approach 2: You will need to make your load data happen in a separate thread then your UI. You will need to load your data in the separate thread and bind it to a list of some sort temporarily, then after its done, bind the list to your Datagrid

Upvotes: 1

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73442

Move your code to Shown event or OnShown overridden method. this will allow your form shown to user before it loads grid.

You should move your "Database calls" to worker threads as well.

protected override void OnShown(EventArgs e)
{
    //Delegate the DB calls to worker threads here 
    //everything will be smooth then..
    base.OnShown(e);
}

Upvotes: 1

user2509901
user2509901

Reputation:

You can use Form Shown event.

Alternatively you can use a different thread to connect to database and show data or use a timer.

Upvotes: 0

nikodz
nikodz

Reputation: 727

Use other thread for loading data from mysql. It's loading form first, but not displaying it until code has finished work.

new Thread(new ThreadStart(LoadDataMethodHere)).Start();

Upvotes: 0

Related Questions