Displaying progress during execution

Hi, I have a small app that updates a bunch of database records. The problem is that this process takes a long time and I'd like to display a simple textbox to show the current percentage complete.

At the moment, I update this textbox in the method that is executing, then call 'this.Invalidate()' then 'this.Refresh()' and it seems to work. Problem I have is when the app is resized or loses focus or whatever, it stops updating. What is the correct way to implement this type of scenario?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed NasmanSoftware DeveloperCommented:
Are u trying to refresh  the textBox on a different thread.
If yes then use Invoke method of ur form to refresh.
As refreshing from other threads is a problem.

e.g. from ur thread use this code

// Define the delegate
delegate void delCallRefresh(object pObject);

// From ur thread use these lines of code
int percentage = 10;
object[] objArray ={percentage};
// here this is reference to ur form
this.Invoke(  new delCallRefresh(this.RefreshTextBox),objArray);

// Define this method in form and refresh the textbox in this method
private void RefreshTextBox(object pObject)
      int percentage = (int)pObject;
      textBox1.Text = percentage.ToString();

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.