Select to view content in your preferred language

Inability to create a progress dialog

1318
4
Jump to solution
12-22-2021 11:07 AM
DaveLewis73
Regular Contributor

I am running into a problem attempting to create a progress dialog.  I have implemented the code below that I found on a thread from this forum, but 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 https://github.com/esri/arcgis-pro-sdk-community-samples/tree/master/Framework/ProgressDialog.  Any thoughts?  Am I missing something?

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

The following is the code that I am using:

            using (ProgressDialog progDialog = new ProgressDialog("Showing Progress", "Canceled", 100, false))
            {
                CancelableProgressorSource cps = new CancelableProgressorSource(progDialog)
                {
                    Max = 100
                };
                progDialog.Show();

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

                progDialog.Hide();
            }

 

0 Kudos
1 Solution

Accepted Solutions
KirkKuykendall1
Frequent Contributor

This works for me ...

protected override async void OnClick()
{
    await Test();
    //If you run this in the DEBUGGER you will NOT see the dialog
    //var ps = new ProgressorSource("Doing my thing...");
    //ps.Max = 5;
    //await ProgressDialogModule.RunProgress(ps, 5);
}
private static async Task Test()
{
    using (var progDialog = new ArcGIS.Desktop.Framework.Threading.Tasks.
                    ProgressDialog("Showing Test Progress", "Canceled", 100, false))
    {
        CancelableProgressorSource cps = new CancelableProgressorSource(progDialog)
        {
            Max = 100                    
        };
        progDialog.Show();
        for (int idx = 0; idx < 10; idx++)
        {
            await Task.Delay(1000);
            cps.Progressor.Value += 10;
            cps.Progressor.Status = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
            cps.Progressor.Message = "Message " + cps.Progressor.Value;
        }
        progDialog.Hide();
    }
}

View solution in original post

0 Kudos
4 Replies
KirkKuykendall1
Frequent Contributor

Are you running in debug mode?


Progress Dialog boxes are disabled when debugging in Visual Studio.

0 Kudos
DaveLewis73
Regular Contributor

Kirk,

Thank you for responding. I actually just came across another thread before you responded that stated that progress dialogs are disabled while debugging in Visual Studio, which is what I am doing.  With that being said, I have just tested the functionality outside of debugging and I see the progress dialog pop up.  However, it is not functioning as it should.  It appears for only a second or two and does not display the progress messages that are in the code.  The dialog does not run for the ten seconds that it is supposed to and doesn't display an update message after each iteration of a second through the loop.  

0 Kudos
KirkKuykendall1
Frequent Contributor

This works for me ...

protected override async void OnClick()
{
    await Test();
    //If you run this in the DEBUGGER you will NOT see the dialog
    //var ps = new ProgressorSource("Doing my thing...");
    //ps.Max = 5;
    //await ProgressDialogModule.RunProgress(ps, 5);
}
private static async Task Test()
{
    using (var progDialog = new ArcGIS.Desktop.Framework.Threading.Tasks.
                    ProgressDialog("Showing Test Progress", "Canceled", 100, false))
    {
        CancelableProgressorSource cps = new CancelableProgressorSource(progDialog)
        {
            Max = 100                    
        };
        progDialog.Show();
        for (int idx = 0; idx < 10; idx++)
        {
            await Task.Delay(1000);
            cps.Progressor.Value += 10;
            cps.Progressor.Status = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed";
            cps.Progressor.Message = "Message " + cps.Progressor.Value;
        }
        progDialog.Hide();
    }
}
0 Kudos
DaveLewis73
Regular Contributor

Thanks again Kirk.

The code worked by getting rid of that await QueuedTask.Run.  I had a feeling that there was probably something with the async code that was causing the problem.  However, as an fyi, I did have to make a couple of slight adjustments, though.  I moved the await Task.Delay(1000); down to the bottom of the loop and I added a line of code to kick out if the progress is canceled.

0 Kudos