Karl
Karl

Reputation: 5733

How can I force a progress bar to update during a long-running operation in VB.NET?

I am running a test program for VB.NET, and it will simply crunch a million numbers in for loop. I've linked a variable implying the progress of the for loop with the progress bar, but it seems that when I run the program, the progress bar does not update itself. The bar itself has only value 0-100 as input (as stated in the document) and I've tested it without using the for loop, and it works.

I think this has to do with threads, but I am not sure how things work in VB.NET exactly yet. So I want to seek an advice from an expert first.

Any advice is appreciated.

Upvotes: 1

Views: 4538

Answers (2)

Grumpy
Grumpy

Reputation: 2243

long time ago but i think you need the DoEvents statement

Upvotes: 1

PaulG
PaulG

Reputation: 14021

Don't know if this still applies for .net (or if this is a VB6 question), but Application.DoEvents was generally the solution in VB6 days.

Try Application.DoEvents inside your loop that updates the progress bar.

Upvotes: 3

Related Questions