3D コンテンツを Viewport3D に非同期的に追加しようとすると、「この API は間違ったコンテキストからの引数でアクセスされました」という結果になります。TargetInvocationException で。
3D コンテンツは、3D スキャン デバイスのデータから生成されます。そのために必要な通信と計算は、別のスレッドで行われます。まず、そのスレッドから viewport3D にアクセスしようとしました。これは GUI スレッドで行う必要があることに気付いたので、次のコードを使用します。
ModelVisual3D model = new ModelVisual3D();
model.Content = scanline;
DispatcherOperation dispOp = this.viewport.Dispatcher.BeginInvoke(
new AddModelDelegate(StartAddModel), model);
}
private void StartAddModel(ModelVisual3D model)
{
this.viewport.Children.Add(model);
//model is not in the context of this current thread.
//Throws exception: "This API was accessed with arguments from the wrong context."
}
private delegate void AddModelDelegate(ModelVisual3D model);
「モデル」という名前のオブジェクトは、現在のスレッドのコンテキストにないようです。どうすればこれを修正できますか? Dispatcher のコンテキストにモデルを取得する方法はありますか? それとも、これを行うこの方法は、ここに行く方法ではありませんか?