Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing file copy program with progress bar showing file copied progress.I have created thread which will do the file reading and writing work.
public partial class FileCopy : Form
{
  onStartButtonClick()
  {
      Thread fileReaderWriter = new Thread(new ThreadStart(doFileCopy));
      fileReaderWriter.Start();
  }
  doFileCopy()
  {
    while(file.length> 0)
    {
      //read data 
      //write data
      reportProgress(someValue);
    }
   MessageBox.show("File Copied");
   disableControl();
  }
  private void disableControl()
  {
    progressbar1.hide();
  }
   private void ReportProgress(int _nValue)
        {
            progressBar1.BeginInvoke((Action)(() =>
            {
                progressBar1.Value = _nValue;
                progressBar1.Update();
            }));

            label4.BeginInvoke((Action)(() =>
            {
                label4.Text = " some Text";
            }));

            label5.BeginInvoke((Action)(() =>
            {
                label5.Text = " Time remaining  " + _lTimeRemaining + " s";
            }));       
        }
}
<pre>
Progress bar is get updated its not hiding the progressbar after file copied message.It get hange on disableControl() method.How can I hide progress bar?
Posted
Updated 12-May-15 2:22am
v2
Comments
Sascha Lefèvre 12-May-15 8:11am    
You don't need to have a separate BeginInvoke for each control - you can call BeginInvoke on any control and then access any other control in its Action-delegate.
Sarita S 12-May-15 8:22am    
ok.I will do that.

1 solution

Why do you call Join on the created thread? That operation causes the UI thread to be blocked until the created thread has finished its work...

 
Share this answer
 
Comments
Sarita S 12-May-15 7:39am    
It worked.Thank you sir

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