Q:

How can i update the progress bar in window application from another class?

I have created one windows form, there i have a progress bar, i want to update the value of progress bar, from another class. I have written one function in my class on its execution, i want to see the progress in progress bar.
For Example:

The code written in forms .cs file:

 namespace UpdateProgressBar
{
    public partial class ProgressBarUdpate : Form
    {
        public ProgressBarUdpate()
        {
            InitializeComponent();
        }

        private void btn_Submit_Click(object sender, EventArgs e)
        {
            UpdateDataProgress updt = new UpdateDataProgress();
            updt.ExecuteFucntion();
        }
    }
}

The code written in another class

namespace UpdateProgress
{
    public class UpdateDataProgress
    {
        public void ExecuteFucntion()
        {
            for (int i = 0; i < 100; i++)
            {

            }

        }
    }
}

My Expected output is when i call updt.ExecuteFucntion function it should update the progressbar values as per loop implemented in another class.

A:

You should use Event in such requirement.
Logic:
As your basic requirement is to update Progressbar (UI) based on current status of execution of a method (which is in class library)
You need to raise an event while executing ExecuteFucntion(). This Event will be Handled at ProgressBarUdpate form.
As you can see in code below, after creating an object of UpdateDataProgress, we are subscribing it's event by updt.ExecutionDone += updt_ExecutionDone;
Thus as soon as That event raised form ExecuteFucntion() it will call updt_ExecutionDone of ProgressBarUdpate where you can suerly update your progress bar.
Update your code as below.
    public partial class ProgressBarUdpate : Form
    {
        public ProgressBarUdpate()
        {
            InitializeComponent();
        }

        private void btn_Submit_Click(object sender, EventArgs e)
        {
            UpdateDataProgress updt = new UpdateDataProgress();
            updt.ExecutionDone += updt_ExecutionDone;
            updt.ExecuteFucntion();
        }

        void updt_ExecutionDone(int value)
        {
            //Update your progress bar here as per value
        }
    }

and class UpdateProgress
    public delegate void ExceutionHandler(int value);
    public class UpdateDataProgress
    {
        public event ExceutionHandler ExecutionDone;
        public void ExecuteFucntion()
        {
            for (int i = 0; i < 100; i++)
            {
                //perform your logic

                //raise an event which will have current i 
                //      to indicate current state of execution
                //      use this event to update progress bar 

                if (ExecutionDone != null)
                    ExecutionDone(i);
            }

        }
    }

