I just started using MonoMac. I have a small window with a window which contains a button and a label, if I click the button a process is started (executing an loop) til the loop is finished, the UI is locked, but I'd like to update the label (or a progress bar in the future) on each round in the loop. What have I to do that such an (asynchronous) workflow works?

有帮助吗?

解决方案

At the moment your code will all be running on the UI thread so there is no way for you to report progress because the thread is busy processing your loop. MonoMac has TPL support so you should be able to leverage it to run your code in the background

Task.Factory.StartNew(() => {
    for (...) 
    {
        ...
        // update UI
        uiControl.BeginInvoke(() => {
            uiControl.Text = "Updated from thread";
        });
    }
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top