How do I execute an async method inside a relaycommand using ArcGIS Pro SDK and MVVM?

المشرف العام

Administrator
طاقم الإدارة
I'm developing a "search tool" dockpane in the ArcGIS Pro SDK using MVVM. I have a button on my dockpane hooked up to a relaycommand in my viewmodel, which trys to call an async method in my model to return a list of results:

/// /// Search results /// private ObservableCollection _searchResults = new ObservableCollection(); public IList SearchResults { get { return _searchResults; } } /// /// Search button command /// private ICommand _searchCommand; public ICommand SearchCommand { get { _searchCommand = new RelayCommand( async() => { SearchResults.Clear(); var results = await DockFindModel.SearchAsync(_selectedSearchableLayer, _searchString); foreach (var item in results) { SearchResults.Add(item); } //notify results have changed NotifyPropertyChanged(() => SearchResults); }, () => bAppRunning); //command will only execute if app is running return _searchCommand; } }However I get the following exception when the relaycommand tries to execute:

An unhandled exception of type 'System.AggregateException' occurred in mscorlib.dll

Additional information: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread.

I've tried a number of things in this thread to try and resolve the issue with no luck. I'm sure running aync methods in a relaycommand is pretty fundamental to the ArcGIS Pro SDK as ESRI recommend you use MVVM, plus a lot of the supplied methods must be ran asynchronously.

Anyone have luck with this? ESRI staff I'm looking in your direction ;)

Thanks.



أكثر...
 
أعلى