I have recently been looking at the ArcGIS Pro SDK to develop some custom apps. When I started using the fine grained API to create functions I soon found that I needed to use Esri’s QueuedTask. For example, if I try to get the table of a feature layer I receive this error:
“This method or property must be called within the lambda passed to QueuedTask.Run.”
This is the way Esri deals with threading and allows the tool to run in the background (called the CIM thread). The samples Esri provide show how to use a Lambda expression when running the query task:
However, the issue here is that at present you can’t ‘Edit and Continue’ anything inside this Lambda expression when debugging. If I pause Visual Studio, make an edit and press play, I receive this error:
“Modifying a statement which contains a lambda expression will prevent the debug session from continuing while Edit and Continue is enabled.”
Enabling Edit and Continue
QueuedTask has a number of overloads and also accepts a delegate of type Func. That’s way more complicated than it sounds – all we need to do is create a variable Func with the type of our function and specify the function to run. Now we can edit our code:
Wrap up
Whilst the above code doesn’t look quite as elegant as a Lambda expression I think the time that will be saved through the ability of being able to Edit and Continue outweighs this. You can see a sample of the code on GitHub.
Posted by David Wilton, Senior Developer, Exprodat.