I need to access a ListBox control while also performing an action requiring a QueuedTask. When access the SelectedItems on the ListBox, I get an error about the ListBox being access outside of the thread that created it.
What are the best ways to get around this? Should I just save the SelectedItems to a List before entering the QueuedTask, or is there a way to access Form controls while in the QueuedTask??
QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN>
<SPAN class="punctuation token">{</SPAN>
Map map <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">string</SPAN> layerName <SPAN class="keyword token">in</SPAN> lstLayers<SPAN class="punctuation token">.</SPAN>SelectedItems<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token">//This is where I get the error</SPAN>
<SPAN class="punctuation token">{</SPAN>
FeatureLayer currentLayer <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetLayersAsFlattenedList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>OfType<SPAN class="operator token"><</SPAN>FeatureLayer<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Where</SPAN><SPAN class="punctuation token">(</SPAN>l <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> l<SPAN class="punctuation token">.</SPAN>Name<SPAN class="punctuation token">.</SPAN><SPAN class="token function">IndexOf</SPAN><SPAN class="punctuation token">(</SPAN>layerName<SPAN class="punctuation token">,</SPAN> StringComparison<SPAN class="punctuation token">.</SPAN>CurrentCultureIgnoreCase<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">FirstOrDefault</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
currentLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ClearSelection</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//end of Queued Task</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>