Has anyone encountered this issue and have a better work around?
Many of the commonly used methods in ArcGIS Pro SDK are required to be run on the 'MCT' thread. The code is wrapped in a QueuedTask.Run block and in most cases, we need to Wait for the result before continuing processing. This is often done with Task.Wait(). However, I've recently ran into a situation where Task.Wait throws an ERROR because the task has a status of TaskStatus.WaitingForActivation. Is this a known issue?
Task t1 = QueuedTask.Run(() =>
{
try { //do some long running work }
catch (Exception eX) { // handle the error }
});
//code added to prevent error
while (t1.Status==TaskStatus.WaitingForActivation)
{
Thread.Sleep(500);
loopCount++;
if (loopCount > 22) // 11 seconds max wait time
{
break;
}
}
if (t1.Status==TaskStatus.WaitingForActivation) { throw new exception("Task failed to Start within 11 seconds."); }
t1.Wait();
Hi
A comment pattern to await the QueudTask is to use the await key word.
Task t1 = await QueuedTask.Run(() =>
{
try { //do some long running work }
catch (Exception eX) { // handle the error }
});
A good resource that documents Pro's Asynchronous programming concepts is available in this wiki:
In you example if we had a line 9, that did more work (e.g., getting t2.Result), would your code Wait till the task is completed before running line 9?