Select to view content in your preferred language

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

140
2
4 weeks ago
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
2 Replies
CharlesMacleod
Esri Regular Contributor

Change BeginInvoke to Invoke and remove the await (I also dont follow why the "async" on the UI delegate - can u remove that also)... See if that makes a difference.

Wolf
by Esri Regular Contributor
Esri Regular Contributor

There is a community sample that shows the usage of ProgressorSource:
arcgis-pro-sdk-community-samples/Framework/ProgressDialog at 15f436c4256bffdba30e7bf2e6f1cb9c8c2eaa8...

0 Kudos