POST
|
But how can I do it to prevent freezing my app when it has to generate many Graphic objects in foreach-loop. private void runButton_Click(object sender, RoutedEventArgs e)
{
var _ = RunCalcAsync();
}
private async Task RunCalcAsync()
{
await Task.Run(() =>
{
\\ long time operation
model.RunCalc();
});
// creating Graphic collection
// it works but foreach loop freeze my app
// even if I make Task from code below
List<Graphic> graphicCollection = new List<Graphic>();
foreach (var item in model.Results)
{
Graphic graphic = new Graphic()
{
Geometry = PolygonFromPoint(new MapPoint(item.X, item.Y)),
};
graphicCollection.Add(graphic);
}
GraphicsLayer resultsGraphicsLayer = map.Layers["results"] as GraphicsLayer;
resultsGraphicsLayer.Graphics.AddRange(graphicCollection);
}
... View more
04-26-2014
12:11 PM
|
0
|
0
|
353
|
POST
|
Hi, I spend whole week and still I can't find the solution. In my code, button click runs long asynchronous operation. After calculation I want add results (which type is List<Graphic>) to my GraphicsLayer. Using ContinueWithMethod and TaskScheduler or Dispatcher works fine for all UI elements for example ProgressBar but not for my resultsGraphicsLayer. Why? Exception: "An exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll but was not handled in user code. The calling thread cannot access this object because a different thread owns it." private void runButton_Click(object sender, RoutedEventArgs e)
{
var _ = RunCalcAsync();
}
private async Task RunCalcAsync()
{
await Task.Run(() =>
{
\\ long time operation
var results = RunCalc();
}).ContinueWith((t) =>
{
GraphicsLayer resultsGraphicsLayer = map.Layers["results"] as GraphicsLayer;
resultsGraphicsLayer.Graphics.AddRange(results); // this line throw an exception :-(
},
CancellationToken.None,
TaskContinuationOptions.None,
TaskScheduler.FromCurrentSynchronizationContext());
} Any help is much appreciated. Thanks! Mike
... View more
04-24-2014
02:09 PM
|
0
|
3
|
3318
|
POST
|
If you do have services in your solution, you can use the GenerateRendererTask to create your renderer, even for a GraphicsLayer. Hi, If above is true, what should I pass to Url property when I want to create renderer for a GraphicsLayer. I didn't find this case in API reference and samples. Mike
... View more
04-11-2014
04:09 PM
|
0
|
0
|
293
|
POST
|
After little change in code above I get what I want. Thanks!
private async Task AddGraphicsToGraphicsLayer()
{
for (int i = 0; i < 100; i++)
{
// time-consuming operation
await Task.Delay(50);
Graphic g = new Graphic()
{
Geometry = GetRandomPolygon(),
};
MyGraphicsLayer.Graphics.Add(g);
}
}
... View more
04-03-2014
04:15 AM
|
0
|
0
|
452
|
POST
|
for (int i = 0; i < 100; i++)
{
Graphic g = new Graphic()
{
Geometry = GetRandomPolygon(),
};
graphics.Add(g);
await Task.Delay(50);
}
MyGraphicsLayer.Graphics.AddRange(graphics);
Mike, I must confess that asynchronous programming is something new to me but if I properly understand in your code you add all polygons to graphics layer after for-loop. My idea was to add each polygon to layer inside loop (using Add method instead of AddRange), because generating polygons takes critical part of time and I want to see results consecutively on the map. Is it possible? Or maybe I misunderstood you sample;-) Cheers! Mike
... View more
04-02-2014
04:18 AM
|
0
|
0
|
452
|
POST
|
Hi, I am new to ArcGIS Runtime SDK for WPF. I want to add a lot of polygons to graphics layer. Is there possibility to do it asynchronously? Each polygon require some time to generate it and I don't want to freeze my map. My idea is user continue navigating map while new polygons are adding in background. Any help is much appreciated. Thanks!
... View more
04-01-2014
10:58 PM
|
0
|
5
|
1462
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|