Deactivate a map tool on sketch completed

1613
3
Jump to solution
11-19-2017 03:03 AM
MaxMax2
Occasional Contributor II

I have a problem with deactivating my custom map tool when sketch is finished.

At now I'm trying to call SetCurrentToolAsync from the OnSketchCompleteAsync of my map tool. But this causes deadlock. Seems like I need to exit from OnSketchCompleteAsync to proceed with changing the current tool.

I want to deactivate the tool when sketch is completed. I didn't found any property in the MapTool class to specify this behavior. Is this possible?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Max,

Try setting the applications current tool to null (or anything else).

If its null then 'explore' mode will be active.

    protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
    {
      //do something productive with the sketch and deactivate
      ArcGIS.Desktop.Framework.FrameworkApplication.SetCurrentToolAsync(null);
      return base.OnSketchCompleteAsync(geometry);
    }

View solution in original post

0 Kudos
3 Replies
by Anonymous User
Not applicable

Max,

Try setting the applications current tool to null (or anything else).

If its null then 'explore' mode will be active.

    protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
    {
      //do something productive with the sketch and deactivate
      ArcGIS.Desktop.Framework.FrameworkApplication.SetCurrentToolAsync(null);
      return base.OnSketchCompleteAsync(geometry);
    }
0 Kudos
MaxMax2
Occasional Contributor II

Hi Sean,

Hmm, seems it works. I marked this method as async and used await for SetCurrentToolAsync, but it caused deadlock somehow.

Thank you!

Asimov
by
New Contributor III

Got into the same issue, couldn't figure out that the deadlock was await's fault.

In any case it still works with the handler marked as async for those who need to keep it, you just need to take away the await statement from the call (even though intellisense will give a warning about it):

protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
    //do something productive with the sketch and await 
    //all the calls needing to be awaited
    ArcGIS.Desktop.Framework.FrameworkApplication.SetCurrentToolAsync(null);
    return true;
}‍‍‍‍‍‍
0 Kudos