I had this method (simplified but I think it provides all the necessary context) . . .
public override Envelope GetExtent()
{
var geometry = GetGeometry();
return GeometryEngine.Instance.Expand(geometry.Extent, 1.5, 1.5, true);
}
But when I used that inside Pro, I was treated to an exception with this stack trace . . .
ArcGIS.Core.ConstructedOnWrongThreadException: This object must be created within the lambda passed to QueuedTask.Run, or on a compatible STA thread.
at ArcGIS.Core.CoreObjectsBase.ValidateThread()
at ArcGIS.Core.Internal.Geometry.EnvelopeBuilder..ctor(Envelope envelope, Boolean getHandle)
at ArcGIS.Core.Internal.Geometry.EnvelopeBuilder..ctor(Envelope envelope)
at ArcGIS.Core.Geometry.GeometryEngine.Expand(Envelope envelope, Double dx, Double dy, Boolean asRatio)
at My.Namespace.MyClass.GetExtent() in D:\Whatever\MyClass.cs:line 106
at My.Namespace.MyOtherClass.AnotherMethod() in D:\Whatever\MyOtherClass.cs:line 167
I found that this avoids that exception . . .
public override Envelope GetExtent()
{
var geometry = GetGeometry();
var extent = geometry.Extent;
var geometryEngine = GeometryEngine.Instance;
var expandTask = QueuedTask.Run(() => geometryEngine.Expand(extent, 1.5, 1.5, true);)
return expandTask.Result;
}
But I'm not constructing anything within that QueuedTask. I think this is just a leaky abstraction in the API, but I'm still somewhat new to async and fear I'm missing something, so I'd appreciate anyone pointing out what I'm constructing or why I've gotta run that method (whose doc doesn't call out the need to call it on the MCT) in a QueuedTask.