this question has answer here:
- c# progress bar percentage 1 answer
i need show percentage of work done method dolongwork() in progressbar using thread.
public string dolongwork(int varname) { thread.sleep(1000000); /*this method take 1 hour return result (say)*/ return "done"; }
dolongwork() method backup of database.you know take more time perform database backup , need show percentage of backup taken on progressbar.thanks
any type of suggestion highly appreciated.
you can use backgroundworker report on progress has elapsed. small example:
/// <summary> /// start new worker /// </summary> void startwork() { var backgroundworker = new backgroundworker(); //make sure worker reports on progress backgroundworker.workerreportsprogress = true; //we want notified when progress has changed backgroundworker.progresschanged+=backgroundworker_progresschanged; //here work backgroundworker.dowork += backgroundworker_dowork; } void backgroundworker_dowork(object sender, doworkeventargs e) { //do long work } progressbar _progressbar = new progressbar(); void backgroundworker_progresschanged(object sender, progresschangedeventargs e) { //when notified progress changed, update progressbar _progressbar.value = e.progresspercentage; }
Comments
Post a Comment