Here is what I would like to do:
- Create a raster layer from a file
- Add the layer to the map
<SPAN class="keyword token">var</SPAN> rlayer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">RasterLayer</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Raster</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"C:/...../myraster.tif"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
- Regenerate the raster (same filename if possible, but I have some flexibility)
- Refresh the raster layer with the newly updated raster file (so that the map is updated)
My problem is that the raster file is still in use (presumably a reference held by the layer). So I can't delete the file or rename it. I tried a few things to try to uncouple the raster from the layer, but no luck. For example ...
<SPAN class="keyword token">var</SPAN> layers <SPAN class="operator token">=</SPAN> mapVm<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">.</SPAN>OperationalLayers<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> raster <SPAN class="operator token">=</SPAN> myRasterLayer<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">;</SPAN>
layers<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Remove</SPAN><SPAN class="punctuation token">(</SPAN>layer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
raster <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
layer <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
System<SPAN class="punctuation token">.</SPAN>GC<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Collect</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I even tried to force garbage collection. I think that may have worked once or twice, but I can't replicate it reliably.
I also tried the local server approach in the <SPAN class="">ArcGISRuntime.WPF.Samples.DynamicWorkspaceRaster</SPAN>
sample, but same result.
Any advice? Maybe I need to take a different approach?