Create a ProgressDialog with ProgressBar

3455
3
Jump to solution
01-23-2020 06:28 AM
RichardReinicke
Occasional Contributor II

Hello,

I'm trying to create a progress dialog that shows a progress value from 0 to 100 %.

Doing some research I found out that ProgressDialog() with CancelableProgressorSource() is able to serve this. My current setting is as follows:

public async void ComponentChangedHandler(Component selectedComponent)
{
    using (var progress = new ProgressDialog("Start Work"))
    {
        var status = new CancelableProgressorSource(progress);
        status.Progressor.Max = 100;
        progress.Show();

        await QueuedTask.Run(() =>
        {
            uint step = 0;
            foreach (var dateRange in dateRanges)
            {
                DoSomeLongWork();
                step += 10;
                status.Progressor.Value = step;
            }
        }, status.Progressor);

        progress.Hide();
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This way I'm getting a nice progress dialog with my dialog message and a bar animation spinning from left to right and back again. What I want is a progress bar filling up from left to right increasing percent progress by 10 in each iteration step.

What am I missing here?

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

When you create the ProgressDialog you have to specify the max steps in the constructor. Like this:

protected override async void OnClick()
{
    using (var progress = new ProgressDialog("Showing Progress", "Canceled", 100, false))
    {
        var status = new CancelableProgressorSource(progress);
        status.Max = 100;
        progress.Show();

        await QueuedTask.Run(async () =>
        {
            uint step = 0;
            for (var idx = 0; idx < 10; idx++)
            {
                await Task.Delay(1000);
                status.Progressor.Value += 10;
                status.Progressor.Status = (status.Progressor.Value * 100 / status.Progressor.Max) + @" % Completed";
                status.Progressor.Message = "Message " + status.Progressor.Value;
            }
        }, status.Progressor);

        progress.Hide();
    }
}

There is also a sample available showing an implementation:  https://github.com/esri/arcgis-pro-sdk-community-samples/tree/master/Framework/ProgressDialog

View solution in original post

3 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

When you create the ProgressDialog you have to specify the max steps in the constructor. Like this:

protected override async void OnClick()
{
    using (var progress = new ProgressDialog("Showing Progress", "Canceled", 100, false))
    {
        var status = new CancelableProgressorSource(progress);
        status.Max = 100;
        progress.Show();

        await QueuedTask.Run(async () =>
        {
            uint step = 0;
            for (var idx = 0; idx < 10; idx++)
            {
                await Task.Delay(1000);
                status.Progressor.Value += 10;
                status.Progressor.Status = (status.Progressor.Value * 100 / status.Progressor.Max) + @" % Completed";
                status.Progressor.Message = "Message " + status.Progressor.Value;
            }
        }, status.Progressor);

        progress.Hide();
    }
}

There is also a sample available showing an implementation:  https://github.com/esri/arcgis-pro-sdk-community-samples/tree/master/Framework/ProgressDialog

DaveLewis73
Occasional Contributor

I realize that this posting is rather old.  However, I am running into a problem attempting to create a progress dialog.  I have implemented the code suggested by Wolf and I get absolutely nothing.  The task delay of 10 seconds works, but I do not see a progress dialog at all.  I have tested this in two different add-ins, including one that was created just to test this functionality.  I have also had a fellow team member test on another computer to no effect.  In addition I have also checked out and tested with the code from the github link that was included by Wolf.  Any thoughts?  Am I missing something?

As an fyi, I am developing with ArcGIS Pro 2.9 (if that means anything).

0 Kudos
AnthonyDunkDatamineDev1
New Contributor II

You cannot see the progress dialog if you run from the debugger.