---
title: "How to work with Progress Bar in winforms"  
description: "How to work with Progress Bar in winforms"  
author: "Anupam Mishra"  
published: 2016-01-18  
updated: 2016-01-20  
canonical: https://www.mindstick.com/forum/33893/how-to-work-with-progress-bar-in-winforms  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 2 minutes  

---

# How to work with Progress Bar in winforms

I want to use [progress bar](https://www.mindstick.com/articles/12747/android-progress-bar) and changed its [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) when [events](https://www.mindstick.com/blog/102/events-in-c-sharp) are running . How to working with progress bar in such situation.please give me a appropriate example.[thank you in advance](https://answers.mindstick.com/qa/40482/why-was-1968-a-year-of-tension-and-turmoil-list-10-events-1-being-the-best-and-10-the-worst-thank-you-in-advance).

## Replies

### Reply by Anupam Mishra

I would like to use a **BackgroundWorker**. Because we have a loop that large in your WinForm it will block and your app will look like it has hanged.Now we are using **BackgroundWorker.ReportProgress()** to see how to report [progress](https://yourviews.mindstick.com/view/284/devotees-arrived-in-prayagraj-while-work-is-still-in-progress) back to the UI thread and progress bar has been changed.

```
using System;using System.ComponentModel;using System.Threading;using System.Windows.Forms;namespace WorkerDemo{    public partial class Form1 : Form    {        BackgroundWorker BackWorker;        Semaphore s = new Semaphore(0, 1);        bool b;        public Form1()        {            InitializeComponent();            BackWorker = new BackgroundWorker();            BackWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);            BackWorker.ProgressChanged += new ProgressChangedEventHandler                  (backgroundWorker1_ProgressChanged);            BackWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler                   (backgroundWorker1_RunWorkerCompleted);            BackWorker.WorkerReportsProgress = true;    
           BackWorker.WorkerSupportsCancellation = true;        }        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)        {   //Progress bar is changed when report progress is changed            progressBar1.Value = e.ProgressPercentage;            label1.Text = "Processing......" +
progressBar1.Value.ToString() + "%";        }        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)        {            if (e.Cancelled)            {                label1.Text = "Task Cancelled.";             }            else if (e.Error != null)            {                label1.Text = "Error while performing background operation.";             }            else            {                label1.Text = "Task Completed...";            }            button1.Enabled = true;            button2.Enabled = false;        }        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)        {            for (int i = 0; i < 100; i++)            {                Thread.Sleep(100);                BackWorker.ReportProgress(i);                if (BackWorker.CancellationPending)                {                    e.Cancel = true;                   
                BackWorker.ReportProgress(0);                    return;                }                else                {                    Thread.Sleep(1000);                }            }            BackWorker.ReportProgress(100);        }        private void button1_Click(object sender, EventArgs e)        {             button1.Enabled = false;            button2.Enabled = true;            BackWorker.RunWorkerAsync();        }         private void button2_Click(object sender, EventArgs e)        {            if (BackWorker.IsBusy)            {                BackWorker.CancelAsync();            }        }         private void button3_Click(object sender, EventArgs e)        {                           s.Release();                label1.Text = "Task Resume.";             }    }}
```

## Output:

![How to work with Progress Bar in winforms](https://www.mindstick.com/mindstickforums/1c11e2bc-040a-44bb-a063-5a886a9bdab8/images/0451e6ab-5b07-4194-a87c-a47578bc7a52.png)**\**

you can also set the property of Progress bar, such like this:

progressbar1.Minimum=0;

progressbar1.Minimum=100; etc.\

\


---

Original Source: https://www.mindstick.com/forum/33893/how-to-work-with-progress-bar-in-winforms

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
