문제

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