• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

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?
1 Solution
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();

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now