Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i need to extract data from ms access table. the table. for example, contained 93 fields and the recordCount is 4000. now, i have 2 progress bar. one for the record count and one for the field. i need to update them while extracting the data but it wont work with backgroundworker. i'm having difficult trying to solve it.
VB
While reader.Read()
    pb.Value += 1
    pb.Refresh()
    frmMain.lblStatusMain.Text = pb.Value & "/" & recordCount
    Application.DoEvents()
    dg.Rows.Add()
    For i = 0 To reader.FieldCount - 1
        dg.Rows(row).Cells(i).Value = reader(i)
        Application.DoEvents()
        If pb2.Value = pb2.Maximum Then pb2.Value = 0
        pb2.Value += 1
        pb2.Refresh()
        Application.DoEvents()
    Next i
    row += 1
End While
Posted

1 solution

Hi.

Try to change the Order of the Reading and the Application.DoEvents()

First the

Application.DoEvents()

then the Hard work ;)

followed by the Progressbar Refresh.

VB
While reader.Read()
    dg.Rows.Add()
    pb.Value += 1
    pb.Refresh()
    frmMain.lblStatusMain.Text = pb.Value & "/" & recordCount
    Application.DoEvents()
    For i = 0 To reader.FieldCount - 1
        Application.DoEvents()
        dg.Rows(row).Cells(i).Value = reader(i)
        Application.DoEvents()  'Maybe this is Useless... anyway it is 1. April, maybe it will work. 
        If pb2.Value = pb2.Maximum Then pb2.Value = 0
        pb2.Value += 1
        pb2.Refresh()
        
    Next i
    row += 1
End While


Here the MS Example: https://msdn.microsoft.com/en-us/library/bd65th41%28v=vs.90%29.aspx[^]

I had used this to get UI refreshes when the Webbrowser Control loaded an new Webpage, to give a littlebit of Timegaps so it felt like responsive.

I remember that I abused DoEvents, in every second line. Serious no April Joke.
Someone had a good lough about it...

Then I added a Thread.Sleep(2) before the Hard Work followed by the DoEvent.

Of course the Sleep will extend the Databasereads, but rather see something happening instead of waiting for any Endresult.

Maybe You could try to put the Database Calls into a Function and use the Doevents when the Function gives feedback...

Happy Coding and Greetings from Stormy Germany...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900