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.
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()
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...