Click here to Skip to main content
15,896,727 members

Progress bar , timer, background worker not working in my windows application

MAU787 asked:

Open original thread
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..
Tags: C#, .NET, BackgroundWorker

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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