Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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:
 
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.
 
private void timer1_Tick(object sender, EventArgs e)
       {
           progressBar1.Value = 10;
       }
this is my function from which i want to start progress bar.
 
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:
 
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 12-Sep-12 21:32pm
MAU7871.6K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Have you set this properties?
 
backgroundWorker1.WorkerReportsProgress = true;
backgroundWorker1.WorkerSupportsCancellation = true;
  Permalink  
Comments
MAU787 at 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 at 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)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 13 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100