Select to view content in your preferred language

ArcGIS Pro 3.3.4 QueuedTask.Run(() => does not start immediately

157
0
02-25-2025 04:31 PM
Labels (1)
RichardDaniels
Honored Contributor

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;
    }
}

t1.Wait();

 

0 Kudos
0 Replies