Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all
i have windows dot net application in which i m capturing image and displaying it in picturebox.
but after capturing i am doing some processing on that image it takes some time
now i want to show progress bar at the bottom of my form until the image is displayed.
i have used background worker also but it is not firing the event:

C#
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
       {
           progressBar1.Value = e.ProgressPercentage;
           // Set the text.
           this.Text = e.ProgressPercentage.ToString();
       }



i have also used the timer for progress bar but that time gets activated after the processing of image.

C#
private void timer1_Tick(object sender, EventArgs e)
       {
           progressBar1.Value = 10;
       }

this is my function from which i want to start progress bar.

C#
private void btnCapture_Click(object sender, EventArgs e)
       {
//with timer
           timer1.Start();
           timer1.Interval = 100;

//or with background worker
backgroundWorker1.RunWorkerAsync();

           try
           {
               btnLogIn.Enabled = true;
               btnLogOff.Enabled = false;
               lblErrorMsg.Text = "";
               if (txtUserName.Text != "")
               {
                   savingPath= "C:/Inspira/SSO/SSOImage.bmp";
                   if (File.Exists(savingPath))
                   {
                       File.Delete(savingPath);
                   }
                   SSOComp.SSO sosObj = new SSOComp.SSO();
                   string sucessStatus = sosObj.Capture(savingPath);
                   if (File.Exists(savingPath))
                   {
                       lblErrorMsg.ForeColor = Color.Green;
                      
                       PicBoxFinger.ImageLocation = savingPath;
                       //after this i want to stop progress bar .                    
                   }
                   else
                   {
                       lblErrorMsg.ForeColor = Color.Red;
                       lblErrorMsg.Text = "Image not Captutred.";
                   }
               }
               else
               {
                   lblErrorMsg.ForeColor = Color.Red;
                   lblErrorMsg.Text = "Please Enter User Name.";
                
               }


              }
           catch (Exception ex)
           {
               lblErrorMsg.Text = ex.Message;
           }
       }</pre>


and background worker code:

C#
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
     {
         for (int i = 1; i <= 100; i++)
         {
             // Wait 100 milliseconds.
             Thread.Sleep(1000);
             // Report progress.
             backgroundWorker1.ReportProgress(i+10);
         }
     }


i want to start the progress bar on capture click till the picture is displayed in picturebox.

thank you
god bless u all..
Posted

1 solution

Have you set this properties?

C#
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
 
Share this answer
 
Comments
MAU787 13-Sep-12 4:02am    
yes i have added this ..it works on any other button click which does not have any other functionality.. but with my function it starts after displaying image
Sushil Mate 13-Sep-12 5:08am    
put btnCapture_Click event code in backgroundWorker1_DoWork & increase your report progress of background thread in between code.

Hope this helps.

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