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?
Asked
Active
Viewed 304 times
1 Answers
2
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";
});
}
});

James
- 80,725
- 18
- 167
- 237
-
Excellent, thank you. But I noticed that during the process my app boosts to 95% CPU usage. – john84 Feb 12 '14 at 13:15
-
Right, I got it, my notification where in the wrong location. Thank you again, – john84 Feb 12 '14 at 13:24