.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Using of Background Worker and Progress bar in .Net Window application

Posted By:Pravin       Posted Date: August 27, 2012    Points: 40    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Background Worker and Progress bar in .Net and how to use it in our window application.

private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)

                                if (dsInput != null)
                                    int intTotCount = dsInput.Tables[0].Rows.Count;
                                    int intDivide = (intTotCount / 100) + 1;
                                    for (int c = 0; c < intTotCount; c++)
                                        objComm = objSqlDal.CreateCommand(objComm, CommandType.StoredProcedure, "InsertAgentsPages");
                                        objSqlDal.AddParameter(objComm, "@AgentName", SqlDbType.NVarChar, ParameterDirection.Input, 500, dsInput.Tables[0].Rows[c]["AgentName"]);
                                        objSqlDal.AddParameter(objComm, "@Date", SqlDbType.Date, ParameterDirection.Input, 150, dsInput.Tables[0].Rows[c]["Date"]);
                                        objSqlDal.AddParameter(objComm, "@PPD", SqlDbType.BigInt, ParameterDirection.Input, 500, dsInput.Tables[0].Rows[c]["PPD"]);
                                        backgroundWorker1.ReportProgress(c / intDivide);             
                                    blnExcelFormat = true;
                                blnExcelFormat = false;
            catch (Exception ex)

        private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
            // Change the value of the ProgressBar to the BackgroundWorker progress.
            progressBar1.Value = e.ProgressPercentage;

            // Set the text.
            this.Text = e.ProgressPercentage.ToString()+"%"  ;

        private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
            this.Text = 100.ToString() + "%" ;
            lblprogress.Text = "100 %";



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend