0

vb.net I have a form(called Form1) that is very slow because it contain datagridview how load data from sql server.As a result the form takes a long time to loaded. So I create a form_Wait and in the load event of Form1 I put

Form_wait.showdialog()
Load_datagridveiw1("Select * from table1")
Form_wait.close()

My problem is the Form_Wait will be appear but the gift inside it (rectangular progress bar) is not showen ? I used VS 2015

Best man
  • 1
  • 3
  • VB.NET has splash screen functionality built in and the splash screen is created and displayed on a secondary thread. That is specifically because the UI thread can't load one form and keep another responsive at the same time. You need to do basically the same thing. – jmcilhinney Dec 13 '20 at 04:24
  • What is the `Form_wait` form doing? If it has a progress bar, then what is it calculating the progress of? It should be obvious that you need to show what the `Form_wait` is doing. Also, your current posted code does not make sense on the last line… `Form_wait.close()` ? … the form is already closed. When using `Form_wait.ShowDialog()` the code will “stop” at that line until the form is closed. Please clarify what you are asking. – JohnG Dec 13 '20 at 06:47
  • If it is slow because there is a lot of data, you could consider [How can we do pagination in datagridview in winform](https://stackoverflow.com/q/2825771/1115360). – Andrew Morton Dec 13 '20 at 10:02

1 Answers1

0

You cannot meaningfully show and animate GIF in a same thread as your UI sits. You would have to use a BackGroundWorker, which is basically a separate thread. Then the animation will work smoothly and the UI thread will run fine too. There are plenty of BackGroundWorker tutorials on the web.

But a huge warning horn rings reading your words. If it is such a huge amount of data causing the slow loading, I would strongly suggest to reconsider how do you fetch the data. Introducing meaningful filters and pagination are basic ways to tackle this.

Oak_3260548
  • 1,882
  • 3
  • 23
  • 41