Select to view content in your preferred language

Making use of the progressor when doing work on the UI thread.

42
0
yesterday
Gfreitag
Emerging Contributor

Hi everyone,

I'm running into an interesting problem when trying to set up a progressor within a QueuedTask. I have some work that needs to be done on a worker thread, and some that needs to be done on the main UI thread. I want to have a progressor that has a message that says how much time is remaining for all the tasks that fall under QueuedTask.

The problem is, QueuedTask doesn't actually wait for the UI thread to be done before it finished executing, and therefore closing the progressor. My code looks something like this:
 

ProgressorSource ps = new ProgressorSource("Updating subprecincts...", false);
    await QueuedTask.Run(async () =>
    {
        Do thing on worker thread...
        
        await Application.Current.Dispatcher.BeginInvoke(async () =>
        {
            Do thing on UI thread...
        });
    }, ps.Progressor);

The bulk of the time-intensive processes is done on the UI thread, but the progressor closes long before it is finished, making it seem like the task completed far before it actually has. How should I account for this, and is there a way to make the progressor actually wait for the UI thread before closing?

Thanks!

Tags (3)
0 Kudos
0 Replies