0

I have the following code:

// does some long math calculation and stores informaiton in calc
calc = new Calculate(Dimensions, (current, total) =>
    {
        var percent = (int)(100 * current / total);

        // updates labels on the UI whilst the calculations run
        // this locks up the UI
        try { lbl_Progress.Text = $"{percent}%"; }
        catch { lbl_Progress.Text = "?%"; }
        finally { lbl_Progress.Refresh(); }
    });

// wait for the above code to finish
UpdateData(calc); // updates labels with now calculated information n calc

calc is a calculation that is being run, and depending on user input, can take from a few seconds to a few minutes. As you can see, I need to update a single label to display percent. Can someone explain how you can run this code, update the label, and not lock up the UI?

I know you can't update the main thread from another thread, so I have looked online, and have been referred to TPL, however, I haven't been able to figure out how to implement the code. Thanks a lot!

0 Answers0