✅ BackgroundWorker getting progress

I have a winform applications and with this I have put a ProgressBar on it. I was manually changing the progress inside functions using
progressBar.Value = <value>
but now that I run my functions in the background using BackgroundWorker, changing that progress is a little harder than I thought. If I am not mistaken the code below is defined as a 'Delegate Invocation' and I use it to run the function I would like to track progress of:
c#
public void ModifyTQWorker(object sender, DoWorkEventArgs e)
{
    try
    {
        object[] args = e.Argument as object[];
        if (args != null && args.Length == 4)
        {
            ClientContext context = args[0] as ClientContext;
            Microsoft.SharePoint.Client.List listObj = args[1] as Microsoft.SharePoint.Client.List;
            string TQNumber = args[2] as string;
            User Raisedby = args[3] as User;

            if (context != null && listObj != null && TQNumber != null && Raisedby != null)
            {
                (sender as BackgroundWorker).ReportProgress(10);
                ModifyTQ(context, listObj, TQNumber, Raisedby);
            }
            else
            {
                MessageBox.Show("One of the parameters was not given for the ModifyTQWorker.", "Error");
            }
        }
    }catch(Exception ex)
    {
        MessageBox.Show($"There was an issue modifying the current TQ.\n{ex.Message}", "Error");
    }
}


How can I give progress better?
Was this page helpful?