I have an issue with ProgressBar being actualized in a separated UI thread...
I have in my program lots of methods, in which I would like to start and stop a progress bar.
Therefore, I put a UI component ProgressBar in my UI and made a model for it, which (after bindings) works fine when called/used standalone in my model classes (i am not working in code behind).
The problem arises when I set my Progress
model property as indeterminate and then call some other methods: the whole works synchronously and the progressbar gets moving only at the end when exiting the main method.
Here an example of what I want to achieve:
public void MyMethod1()
{
StartProgress();
NormalSubMethod1();
NormalSubMethod2();
(...)
EndProgress();
}
public void MyMethod2()
{
StartProgress();
NormalSubMethod5();
(...)
EndProgress();
}
and here is how my StartProgress()
looks like, with what i've tried without success:
public async void StartProgress()
{
//Task.Run(() => { Progress.IsIndeterminate = true; });
//await Task.Run(() => Progress.IsIndeterminate = true); // starts moving
}
public async void StopProgress()
{
Progress.IsIndeterminate = false; // stops moving
}
I know this has to be a problem of not correctly using the async
, await
and Task
things, but I could not yet get it to work. May anyone please help me providing me a hint on how can I accomplish this?