2
votes

I'm developing a C#.NET (4.0) WinForms application. On startup I want to have a splash screen that fills a series of datagridviews on a different form.

At the moment the main form loads that data into the DataGridViews on Form_Load but this makes the Form hang there while this is happening.

So how do I call the method that loads the values to the DataGridView from the splash screen?

I'm rather new to C#.NET, I'm trying to move away from VB.

1
possible duplicate of C# Splash Screen ProblemHans Passant

1 Answers

4
votes

I would have the splash screen launch the real form where the DataGridViews are, and in that form put the data loading method on its own thread. For a nice and simple and beginner way, use a BackgroundWorker. For more advanced control use Threading.

How to use background worker.

Threading Class Docs

Very good tutorial on threading

EDIT:

As you mentioned in your comment it sounds like you still don't want the form to even appear until its done loading in the data. The easy way to do this is have the main form be hidden from startup, and in the on-load event launch the splash screen, and then when the method that does the data loading returns, set the visibility to true and close the splash screen form. There are many ways to have a form start hidden. Here is a good forum question with lot of answers on different ways to do it.