Is QueuedTask.Run thread safe? Is it not intended for multi-threaded environment and we have to implement our own locking mechanism?
Was getting weird error where:
Have method1, and method2.
Each are async methods and within the body of the method, they have QueuedTask.Run(() => { });
The thing is they may both run in a multithreaded context because they may get called concurrently.
When that happens, sequence of call may be:
Method1 gets called, and while method1 is executing within the QueuedTask.Run body, method2 gets called and executes its QueuedTask.Run body.
Method2 exits the QueuedTask.Run body first while method1 is still inside QueuedTask.Run body.
But it seems the exit of QueuedTask.Run body by method2 is causing method1 to exit out of its QueuedTask.Run body (or something)... method1 tries to execute one of the methods within its QueuedTask.Run body, one of the built-in ArcPro SDK functions such as (LayerFactory.Instance.CreateGroupLayer(MapView.Active.Map, 0, containerName)) and it just hangs...
In debug mode, after stepping over the statement it just seem to exit out of the QueuedTask.Run body or hang or something. It's stuck and have to stop the debug mode execution in VS. When run in non-debug mode, the ArcPro app just gets stuck and have to use task manager to stop the executable.
Current workaround is to use custom SemaphoreSlim implementation and acquire lock before the QueuedTask.Run body is run on both methods, so that those 2 methods never run simultaneously...
But there appears to be multiple method signatures for QueuedTask.Run. Is there perhaps a different call signature for it that would avoid this issue or somthing..?