reichard

I'm running into problems with my forms taking a long time to load (they have datagridviews on them). I think it might be an issue with the number of records I have in the data tables and the time needed to load that data into the datagridviews. Is there a way for me to load all the data when the program initially starts so when the forms are opened, the data has already been loaded and would possibly run faster

Thanks,

John



Re: Visual Basic Express Edition Loading Data at Start-up?

arindam giri

First look from the usuability way. Is it really necessary to load when your program starts You can load your form, then you can keep a button giving user informed that loading data might take some time....press ok to continue...like that. This way I think you can proceed. OR if your table contains thousands of records then don't just load all, you can load say, first 100 records and notify user that "100 records displayed" and keep a button to display all.

Cheers.





Re: Visual Basic Express Edition Loading Data at Start-up?

js06

You could maybe load your forms at the startup and instead of closing them each time, you just use the visible property. You might have to play around with changing the topmost property when you make visible or hide to ensure that the correct form is on top.

In your startup you could also use application.doevents

This will give you some functionality while everything is loading. This creates pauses to allow for mousemovement etc...

You might even look into multithreading or using a timer which i believe run on a seperate thread. or a process or background worker.

If your program is set up in a way that you can predict what forms may come next you might be able to load those forms in the background and have them ready when they move on. This would help if when you load all the forms at one time it drains your resources and makes your program slow. I guess a way to predict the forms coming up would be to set it up as a tier or pyramid where you can access the next set of forms only from the current form instead of say the parent form or a menu.

Just some thoughts, hope they help






Re: Visual Basic Express Edition Loading Data at Start-up?

MS Johan Stenberg

There are some tips here: http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/default.aspx

I would stay away from Application.DoEvents. See Jessica's explanation of why here: http://blogs.msdn.com/jfoscoding/archive/2005/08/06/448560.aspx

Best regards,

Johan Stenberg






Re: Visual Basic Express Edition Loading Data at Start-up?

reichard

I'm thinking that using a backgroundworker is where I need to go. The problem is, I'm very confused on how to use a backgroundworker. I've looked up how to use a backgroundworker and the examples shown seem very complex. All I want to do is open a form, then hide it so when the user wants to open the form later, I can just unhide the form rather than load it at that time. Here is what I have so far, but nothing seems to work. I think I am missing something very basic to the backgroundworker, but I don't know what it is.

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

Catalog_Form.Show()

Catalog_Form.Visible = False

MessageBox.Show("Form has loaded")

End Sub

Is there another Sub I need to call

Thanks,

John





Re: Visual Basic Express Edition Loading Data at Start-up?

js06

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.BackgroundWorker1.RunWorkerAsync()

Me.BackgroundWorker1.WorkerSupportsCancellation = True

End Sub

you just have to start the background worker

the second line is if you want to cancel the worker at some point you can add the cancel code somewhere else maybe in the formclosing event

i'm not sure how the worker is handle when the application exits