2

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.

JustLearning
  • 37
  • 1
  • 7
  • possible duplicate of [C# Splash Screen Problem](http://stackoverflow.com/questions/392864/c-sharp-splash-screen-problem) – Hans Passant Apr 14 '13 at 23:41

1 Answers1

4

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.

FrostyFire
  • 3,212
  • 3
  • 29
  • 53
  • Thanks!That seems like a simple enough approach. Unless this way would already do it, how do I make the form only display after all grids have finished loading? – JustLearning Apr 15 '13 at 00:27
  • Well by putting it on its own thread the UI and the data loading are on separate threads which means your from will not hang anymore. I thought that was your question. See my edit from the comment question – FrostyFire Apr 15 '13 at 22:52