06-27-2020 02:10 PM
Occasional Contributor


I have a tool that does layout for an application.  The sketch type is a line.  For each click in the map a node is created.  This is done in an await QueuedTask.Run(...).

Since the call is done in the OnSketchModifiedAsync method (something I found in one of the samples led me to this approach.

However, I need to prevent "re-entry" meaning I don't want to create another QueuedTask until the first one is completed.  I've observed that re-entry causes some very weird behaviors with layout.

What I originally tried is this (as the first code in the method):


    await Task.Yield();

My manager flagged the use of this questioning whether it is valid.  So I ask here, is this valid?  If not, what is the alternative?

Until I get an answer one way or the other, I have come up with an alternative.  I added a private boolean property to the tool called IsExecuting.  This is set to true just before calling await QueuedTask.Run(...).  Then immediately following that I am calling IsExecuting=false.  At the start of the method I check to see if it is true and then return true for the method.  According to the intellisense, this means the method is handled.  This seems to behave in similar fashion to the while loop.  But I feel the while loop works better.

I have found no snippets samples or discussion about using QueuedTask.Busy anywhere.  But since the property is there, it must be used somewhere.  It seems how I use it with the while loop is valid.

I did find in the samples a check of QueuedTask.OnWorker.  It only appears once in all the samples and I did not find any code snippets or examples in the Github wiki.



0 Kudos
0 Replies