<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic DelayedInvoker example in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/delayedinvoker-example/m-p/1488913#M11645</link>
    <description>&lt;P&gt;I recently started doing some custom map editing development and have a tool where I want to show some overlay graphics as the user moves their mouse around.&amp;nbsp; The overlay stuff works well but if I just redraw on every mouse move event, it takes too long to process the redraw and it lags behind the mouse cursor.&amp;nbsp; I saw there's a DelayedInvoker class that sounds like it's meant to support these kinds of situations but the documentation is very light and I don't see any examples of how it would be used.&amp;nbsp; For now, I implemented my own method where I push all coordinates from the mouse move even to a stack and then once a redraw is done, it can pop the most recent coordinate from that stack and remove/ignore any points it wasn't able to process while it was drawing.&amp;nbsp; It works well but if there's already something that is able to provide a similar function, I would love to use that instead.&amp;nbsp; Does anyone have any examples of using the DelayedInvoker for mouse move events?&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jun 2024 14:48:36 GMT</pubDate>
    <dc:creator>BillyBuerger</dc:creator>
    <dc:date>2024-06-11T14:48:36Z</dc:date>
    <item>
      <title>DelayedInvoker example</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/delayedinvoker-example/m-p/1488913#M11645</link>
      <description>&lt;P&gt;I recently started doing some custom map editing development and have a tool where I want to show some overlay graphics as the user moves their mouse around.&amp;nbsp; The overlay stuff works well but if I just redraw on every mouse move event, it takes too long to process the redraw and it lags behind the mouse cursor.&amp;nbsp; I saw there's a DelayedInvoker class that sounds like it's meant to support these kinds of situations but the documentation is very light and I don't see any examples of how it would be used.&amp;nbsp; For now, I implemented my own method where I push all coordinates from the mouse move even to a stack and then once a redraw is done, it can pop the most recent coordinate from that stack and remove/ignore any points it wasn't able to process while it was drawing.&amp;nbsp; It works well but if there's already something that is able to provide a similar function, I would love to use that instead.&amp;nbsp; Does anyone have any examples of using the DelayedInvoker for mouse move events?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 14:48:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/delayedinvoker-example/m-p/1488913#M11645</guid>
      <dc:creator>BillyBuerger</dc:creator>
      <dc:date>2024-06-11T14:48:36Z</dc:date>
    </item>
    <item>
      <title>Re: DelayedInvoker example</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/delayedinvoker-example/m-p/1488995#M11646</link>
      <description>&lt;P&gt;The pattern looks something like this but I dont think it is going to give u the results you are hoping for:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class MapTool1 : MapTool {

    private DelayedInvoker _invoker = new DelayedInvoker(50);
    ...

    protected async override void OnToolMouseMove(MapViewMouseEventArgs e){
       //do something with the invoker
       _invoker.InvokeTask(() =&amp;gt; {
            return QueuedTask.Run(() =&amp;gt; {
		var mpt = MapView.Active.ClientToMap(e.ClientPoint);
                //Do something with the point
             });&lt;/LI-CODE&gt;&lt;P&gt;Basically, just like a "QueuedTask.Run(() =&amp;gt; { ........... })" you can wrap whatever u want to be invoked with the delay (50ms in this case) within the "_invoker.InvokeTask" lambda. So, in this case, if I am tracking the cursor position w/ the invoker I will be "processing" its position every 50ms (or whatever delay u specify) which will be quite jittery and so on.&lt;/P&gt;&lt;P&gt;In the Pro SDK are a number of samples where we implement logic to cut down on unnecessary mouse movement - just search for "MouseMove" and you will see them - they are all using the same, basic pattern and are updating the graphics overlay in different ways.&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/search?q=repo%3AEsri%2Farcgis-pro-sdk-community-samples%20mousemove&amp;amp;type=code" target="_blank"&gt;https://github.com/search?q=repo%3AEsri%2Farcgis-pro-sdk-community-samples%20mousemove&amp;amp;type=code&lt;/A&gt;&lt;/P&gt;&lt;P&gt;I suggest using something built around the pattern they are using rather than the delayed invoker.&lt;/P&gt;&lt;P&gt;Another way, that I have used from time to time, is this basic pattern:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class SelectOnMove1 : MapTool
{
	private Point _lastLocation;
	private int _deltaPixels = 0;

   protected override Task OnToolActivateAsync(bool active) {
     if (_deltaPixels == 0)
      //usually 3 pixels - use whatever number u want
       _deltaPixels = SelectionEnvironment.SelectionTolerance;


  protected async override void OnToolMouseMove(MapViewMouseEventArgs e) {
    //compare current cursor position to last (captured) position
    if (_lastLocation.X &amp;gt;= e.ClientPoint.X - _deltaPixels &amp;amp;&amp;amp;
        _lastLocation.X &amp;lt;= e.ClientPoint.X + _deltaPixels &amp;amp;&amp;amp;
        _lastLocation.Y &amp;gt;= e.ClientPoint.Y - _deltaPixels &amp;amp;&amp;amp;
        _lastLocation.X &amp;lt;= e.ClientPoint.X + _deltaPixels)
           return;//within tolerance - ignore

     _lastLocation = e.ClientPoint; //we'll use this one
     //TODO - use the point
   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it is going to be v difficult to get truly smooth tracking and it will always be a little laggy/jittery. Your mileage will vary.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 17:54:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/delayedinvoker-example/m-p/1488995#M11646</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2024-06-11T17:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: DelayedInvoker example</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/delayedinvoker-example/m-p/1489006#M11647</link>
      <description>&lt;P&gt;Thanks, this is very helpful.&amp;nbsp; Since the documentation on DelayedInvoke doesn't give much information, I wasn't sure if it was the right thing to use or not.&amp;nbsp; Your description and example help a lot.&amp;nbsp; I was just reviewing some of the MouseMove examples in the ProSDK examples.&amp;nbsp; Not sure how I missed or forgot those when I was working on this.&amp;nbsp; It seems what I did is similar to those examples so I think I'm good.&amp;nbsp; The redraw is pretty quick smooth on my system.&amp;nbsp; Although we'll see how it performs on slower VDIs and such where performance can be lacking.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jun 2024 18:14:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/delayedinvoker-example/m-p/1489006#M11647</guid>
      <dc:creator>BillyBuerger</dc:creator>
      <dc:date>2024-06-11T18:14:02Z</dc:date>
    </item>
  </channel>
</rss>

