Im trying to update a progress bar while doing some data type checks on a separate thread and there seems to be a delay between what value the progress bar is at and the value which is actually show.
The following code is executed by the non-GUI thread and is used to raise the event.
    protected virtual void OnUpdateProgressBar(object sender, ProgressBarEventArgs e)
    {
        EventHandler<ProgressBarEventArgs> TempHandler = UpdateProgressBar;
        //Avoid possible race condition.
        if (TempHandler != null)
        {
            TempHandler(this, e);
        }
    }
I have created a separate class for updating the progress bar and when i create an instance of it, i pass a reference to the progress bar. Below is the entire class.
public class ProgressBarChanged
{
    ProgressBar statusBar;
    public ProgressBarChanged(ProgressBar pb)
    {
        statusBar = pb;
        statusBar.Value = 0;
    }
    public ProgressBarChanged()
    {
    }
    public void subscribeToEvent(DataVerification test)
    {
        test.UpdateProgressBar += new EventHandler<ProgressBarEventArgs>(incrementPB);
    }
    public void incrementPB(object sender, ProgressBarEventArgs e)
    {
        Action action = () =>
        {
            if (e.CurrentRow == e.FinalRow - 10)
            {
                int i = 5;
            }
            statusBar.Maximum = e.FinalRow;
            statusBar.Value = e.CurrentRow;
        };
        if(statusBar.InvokeRequired)
           statusBar.Invoke(action);
        else
            action();
    }
}
I have uploaded a screen shot showing the progress bar and the actual values. Any ideas???
Thanks
