1

InvalidOperationException を取得するサードパーティ ツールを使用しています (実際には、これは PresentationFramework.dll で発生します)。

別のスレッドがこのオブジェクトを所有しているため、呼び出し元のスレッドはこのオブジェクトにアクセスできません。

BeginInvoke を含め、Invoke を使用してあらゆる種類のバリエーションを試しましたが、何も変わりません。

セッション session = new ThirdPartyTool.Session();
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => session.Open(view)));

Google を使用する場合、Invoke の使用を提案する「解決策」しか見つかりません。まあ、私はInvokeを使います。
ここのstackoverflowに関する他の質問とそれぞれの回答も役に立ちませんでした。

実際の原因を突き止めるにはどうすればよいですか?


編集:スレッドウィンドウをもう一度調べたところ、完全なコールスタックがメインスレッドにあります。私の知る限り、これは Invoke が不要であることを示しています。


Edit2:
open を呼び出してもエラーは直接発生しません。ThirdPartyTool はリスト ボックスを初期化し、このリスト ボックスを測定すると、プレゼンテーション フレームワークでエラーが発生します。

ここに画像の説明を入力

実際の例外は XamlParseException にラップされます。完全な例外の詳細:

System.Windows.Markup.XamlParseException occurred  
HResult=-2146233087  
Message=The calling thread cannot access this object because a different thread owns it.  
Source=PresentationFramework  
LineNumber=0  
LinePosition=0  
StackTrace:  
  at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)  
InnerException: System.InvalidOperationException  
  HResult=-2146233079  
  Message=The calling thread cannot access this object because a different thread owns it.  
  Source=WindowsBase  
  StackTrace:  
    at System.Windows.Threading.Dispatcher.VerifyAccess()  
    at System.Windows.Freezable.get_IsFrozen()  
    at System.Windows.Controls.Image.UpdateBaseUri(DependencyObject d, ImageSource source)  
    at System.Windows.Controls.Image.OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)  
    at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)  
    at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)  
    at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)  
    at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)  
    at System.Windows.FrameworkTemplate.ReceivePropertySet(Object targetObject, XamlMember member, Object value, DependencyObject templatedParent)  
    at System.Windows.FrameworkTemplate.<>c__DisplayClass6.<LoadOptimizedTemplateContent>b__4(Object sender, XamlSetValueEventArgs setArgs)  
    at System.Xaml.XamlObjectWriter.OnSetValue(Object eventSender, XamlMember member, Object value)  
    at System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)  
    at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)  
    at System.Xaml.XamlObjectWriter.Logic_AssignProvidedValue(ObjectWriterContext ctx)  
    at System.Xaml.XamlObjectWriter.WriteEndObject()  
    at System.Xaml.XamlWriter.WriteNode(XamlReader reader)  
    at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)  
  InnerException: null
4

2 に答える 2

6

I'd hazard a guess and suggest that you don't use invoke: just call session.Open from where you are.

I say that because - if your session object has thread affinity - you've just created it on whatever the current thread is, and so the Open call needs to be on the same thread. Your Invoke is potentially pushing the call elsewhere.

Alternatively, it could be that some other code is causing the problem. If that's the case then you could instead try this to create the object on whatever the dispatcher thread is:

Session session = null;
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal,
    (Action)(() => { 
                     session = new ThirdPartyTool.Session();
                     session.Open(view);
                   } ));
于 2013-06-07T09:59:06.200 に答える
1

レーダー画面から外れた画像が問題の原因であることが判明しました。に電話するとFreeze、問題は解消されました。

于 2013-09-12T13:44:32.573 に答える