How to cannel the MCT method with code?

242
1
08-18-2024 09:44 AM
Werk
by
New Contributor

HI,

I'm using the ArcGIS Pro SDK to develop plugins and the user specifies my workflow.

I'm a little confused about the use of the multithreaded model right now, and I'm sorry I'm not very familiar with it.

I know from the wiki that the ArcGIS Pro SDK has quite a few methods that need to be called from within the MCT process, that is, using QueuedTask.Run(). I also know from being in this section ProConcepts Framework · Esri/arcgis-pro-sdk Wiki (github.com) that there are some instructions about task canceling, but I'm still confused about task canceling.

Currently my referenced scenarios have to call methods in the MCT process, i.e. they have to be called in the QueuedTask, but some of the methods take a long time to execute and I want to be able to cancel them manually, but I've found that CancelableProgressorSource.Cancel() seems to be available only in the Cancel button of the interface, which I'm not so sure about.

Werk_0-1723999420777.png

 

I was wondering if esri could provide a definitive answer as to whether I can do a manual cancel via code for the specified executing MCT method? If so, could you provide some sample code?

Tags (3)
0 Kudos
1 Reply
UmaHarano
Esri Regular Contributor

@Werk 

Check out this community sample that illustrates how to use ProgressDialog and CancelableProgressorSource to accomplish what you need: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Framework/ProgressDialog 

Here is a small code snippet that highlights this:

 

//on a Pro button click on the ribbon
protected override async void OnClick()
{
 var pd = new ArcGIS.Desktop.Framework.Threading.Tasks.ProgressDialog(
        "Processing...", 10, false  );
 var progressorSource = new CancelableProgressorSource(pd);
 progressorSource.Max = 10;
 await QueuedTask.Run(() =>
 {
    if (progressorSource.Progressor.CancellationToken.IsCancellationRequested)
            return;  
    //Do business logic
    progressorSource.Progressor.Value += 1;
progressorSource.Progressor.Message = "...";
 });
}

 

0 Kudos