Link to home
Start Free TrialLog in
Avatar of ThomasBoardman
ThomasBoardman

asked on

Using Backgroundworker to show progressbar in Form1 while Form2 loads

I am trying to display a progressbar in Form1 while Form2 loads using VB 2005.  Once Form2 loads, I want to  hide Form1.  The most important aspect of this task is that I do not want to have a counter or timer controlling the progress of the progressbar.  Since Form2 could take between 30-90 seconds to load, I want to update the progressbar from the Load event for Form2.  I have struggled using delegate and invoke to update the progressbar with no success.  I have found a similar example on this site, but the example uses a counter to update the progress bar.  Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you really want to hide Form1?   Or do you want Form1 to completely close and have Form2 now be the main form of the application?
Avatar of ThomasBoardman
ThomasBoardman

ASKER

Once again, Idle Mind, your suggestion did the trick!  I want to hide Form1 since it takes awhile to load, and it contains the main menu for my ap.

Tom
Hello i have one problem(and who not have one):) well, is it pretty similar my question

I have a form called Form1, ok?, well this form calls a procedure(named LoadData())from where i get some data from a database.

What I want are : when this procedure is called, a new instance of a form, called form2 that contains a simple progressbar with marquee style is displayed(do not report progress). and when the procedure ends the form2 will close.

While LoadData() procedure is running the original Form1 must to be locked or hidden to avoid errors or multiple calls of LoadData() procedure.

I don't want to use cancel or report progress events of a BackGroundWorker. or IsBusy property.
Ok...I don't see a "problem" there...

Just do it just like you've outlined:

    ' ...within Form1...
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Enabled = False

        Dim f2 As New Form2()
        f2.Show()

        LoadData() ' <-- this loads your data by starting the BackgroundWorker

        f2.Close()
        Me.Enabled = True
    End Sub
hmmm, tanks but, if you try to do this, your app will look frozen if don't use a thread o backgroundworker or doevents, I been trying using something like in the solution posted, but my app continue looking frozen
i use this:

//The main form from i launch this code
This.Hide();
//The progress form
Form2.Show();

//Consuming time operation
DataTable tbl = Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers();

Application.DoEvents();
Form2.Close();
This.Show();

I to know the use of DoEvents() it supouse this sentence is used into a loop , but here in this particular case, all has been reduced to a single line, any sugestion?
"...your app will look frozen if don't use a thread o backgroundworker or doevents..."

Well...yeah, and I thought you already knew that from YOUR statement:

    "I don't want to use cancel or report progress events of a BackGroundWorker."

This IMPLIED that you were in fact using the BackgroundWorker() control...which would alleviate the "frozen" problem.
hmm i think you are right let me think about it, tanks