Frage

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?

War es hilfreich?

Lösung

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";
        });
    }
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top