arcgis wpf: QueryTask Crashes on query completed net 4.0 big solution

3938
10
02-04-2014 02:24 AM
Labels (1)
DamirImangulov
Emerging Contributor
Product: ArcGis 10.2 WPF Runtime

Hi, I'm using Featurelayer. On computers with NET 4.5 everything works fine. But computers NET 4.0 is an error.

Catching Unhandled exception
System.AggregateException: 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. ---> System.InvalidOperationException: The calling thread cannot access this object because a different thread owns it.
at System.Windows.Threading.Dispatcher.VerifyAccess()
at System.Windows.DependencyObject.GetValue(DependencyProperty dp)
at ESRI.ArcGIS.Client.GraphicsLayer.<Graphics_Collectionchange d>b__1(Graphic a)
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at ESRI.ArcGIS.Client.GraphicsLayer.Graphics_Collectionchange d(Object sender, NotifyCollectionchange dEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionchange d(NotifyCollectionchange dEventArgs e)
at ESRI.ArcGIS.Client.GraphicCollection.AddRange(IEnumerable`1 items)
at ESRI.ArcGIS.Client.FeatureLayer.task_QueryComplete(Object sender, QueryEventArgs args)
at ESRI.ArcGIS.Client.Tasks.QueryTask.OnExecuteCompleted(QueryEventArgs args)
at ESRI.ArcGIS.Client.Tasks.QueryTask.<>c__DisplayClassf.<ExecuteAsync>b__d(Task`1 result)
at ESRI.ArcGIS.Client.Tasks.TaskBase.<>c__DisplayClassc`1.<HandeEventBasedTask>b__a(Task`1 result)
at System.Threading.Tasks.Task`1.<>c__DisplayClass17.<ContinueWith>b__16(Object obj)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()

and so on ...

The most interesting cases looked similar to the network, I'm not the first to face such a problem, but to repeat it in a small decision can not.

Disassembled assembly ArcGis proved that there QueryTask class call the base class.

public void ExecuteAsync(Query query, object userToken = null)
        {
            Action<Task<QueryResult>> isFaulted = (Task<QueryResult> result) => {
                if (result.IsFaulted)
                {
                    this.LastResult = null;
                    return;
                }
                this.LastResult = result.Result.FeatureSet;
                QueryEventArgs queryEventArg = new QueryEventArgs(result.Result.FeatureSet, result.Result.ExceededTransferLimit, userToken);
                this.OnExecuteCompleted(queryEventArg);
            };
            base.HandeEventBasedTask<QueryResult>((CancellationToken ct) => this.ExecuteTaskAsync(query, ct), Resources.QueryTask_Error, isFaulted, userToken);
        }

HandeEventBasedTask turns out he is responsible for returning to the desired flow! and what we see inside the method

taskToExecute(token).ContinueWith((Task<R> result) => {
                    ... some code
                }, TaskScheduler.FromCurrentSynchronizationContext());

To return to the calling thread is used method TaskScheduler.FromCurrentSynchronizationContext (), but there's a bug in NET 4.0, NET 4.5 and all perfectly fulfills.

Help please, you only need to change this piece of code that all worked perfectly in both fremvork. If I need help with those kind of logic there references.

!!! reproduced
0 Kudos
10 Replies
MichaelBranscomb
Esri Frequent Contributor
Hi,

We have been investigating the implications of the underlying .NET 4.0 issue in our API and we plan to include a fix in the next release of the ArcGIS Runtime SDK for WPF, which will be 10.2.2. However, in line with the end of support from Microsoft for Windows XP on 8th April 2014 we issued the deprecation notice last year announcing 10.2 would be the last release to support Windows XP (and Windows Vista). The next release will continue to built for .NET 4.0.

Regards

Mike
0 Kudos