The solution to this is probably fairly simple but I can't seem to find it anywhere, even in code samples. I create a task that will pass back a polyline that the task creates. I declare the polyline locally, but I am unable to assign anything to it, not even able to do "= new polyline();", so what happens is the polyline needs to be created in the QueuedTask, but the line to return that polyline at the end of the function (outside of the QueuedTask) doesn't recognize that so the code fails. If I put the return statement inside the queuedtask then that error clears up, but the function definition itself has an error that "not all code paths return a value". I can also only create the polyline within a queuedtask. Is there a way around this? It seems like something that would be used pretty often. Is it just not possible to create a Task with a geometry? The sample below is what I'm seeing:
async Task<Polyline> CreateLineAtClickPoint(MapPoint m)
{
Polyline pLineClickLoc;
List<MapPoint> LinePoints = new List<MapPoint>();
MapPoint LineStart;
MapPoint LineEnd;
await QueuedTask.Run(() =>
{
togSR = SpatialReferenceBuilder.CreateSpatialReference(2868);
if (StreetQueryIsEW)
{
LineStart = MapPointBuilder.CreateMapPoint(LineXMin, m.Y, togSR);
LineEnd = MapPointBuilder.CreateMapPoint(LineXMax, m.Y, togSR);
}
else
{
LineStart = MapPointBuilder.CreateMapPoint(m.X, LineYMin, togSR);
LineEnd = MapPointBuilder.CreateMapPoint(m.X, LineYMax, togSR);
}
LinePoints.Add(LineStart);
LinePoints.Add(LineEnd);
pLineClickLoc = PolylineBuilder.CreatePolyline(LinePoints);
});
return pLineClickLoc; //has error "unassigned local variable"
}
I have created tasks with mappoints, like below, but I had to "fudge in" a value to assign the point, like in the sample below, but I can't do that with the polyline. I don't really like doing that with the mappoint either, it seems rather sloppy (but it does work).
async Task<MapPoint> UnprojectCoordinates(MapPoint p)
{
MapPoint up = MapPointBuilder.CreateMapPoint(0, 0); //just assign 0,0 to the point to get started, avoid error
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
togSR = SpatialReferenceBuilder.CreateSpatialReference(2868);
SpatialReference srWGS84 = SpatialReferenceBuilder.CreateSpatialReference(4326);
ProjectionTransformation trTOG2WGS84 = ProjectionTransformation.Create(togSR, srWGS84);
up = GeometryEngine.Instance.ProjectEx(p, trTOG2WGS84) as MapPoint;
});
return up;
}
If there's anything that I can do to resolve this, thank you in advance for assisting me.
Jeff