Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir
I am uday satardekar

In my c sharp winform application,i am trying to show progressbar for long running process which take more than one minute.

But this time is unknown.so how i can show progressbar for that
Thanks .........
Posted

 
Share this answer
 
Comments
udusat13 27-Aug-11 3:00am    
I am getting confused regarding backgroundworker.

on my button click i am calling following long running method

if (checkValidRowsEmails() == true && validation())
{
addDataUsingXml1();
}



please help me
In response to your comment in Solution 1, here is my solution...

Essentially, you simply drop a background worker from the toolbox unto the the form and then hook up events and set properties as required. In your button click handler, you tell your background worker to start and you use its ReportProgress to report progress to the UI thread.

Since your duration is inderminate, you can set the appropriate style on the progress bar... or you might somehow try to find a way to estimate how long it would take. For example, you might uses the time taken to do some initial step and uses some ratio to estimate the total time. Add an extra 5% to that and if at the end of time, it is still not completed, set the progress bar in the indeterminated state again.

All steps are clearly explained here. Although that example if for Silverlight, it is essentially the same on WinForms (but you can hook events with the designer).

How to: Use a Background Worker[^]
 
Share this answer
 
Comments
udusat13 30-Aug-11 2:15am    
Thanks Sir,
According to article I have modified code like following

public TestForm()
{
InitializeComponent();
backgroundWorker1.WorkerReportsProgress = true;
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{

// backgroundWorker1.ReportProgress();
uploadUsingText();
}
}

private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}

private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}

but progress bar value remained same
Philippe Mori 30-Aug-11 8:28am    
You have to specify the percentage in ReportProgress.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900