Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3497066
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:19:32+00:00 2026-05-18T12:19:32+00:00

When I try to add 3D-content to a Viewport3D, asynchronously, this results in This

  • 0

When I try to add 3D-content to a Viewport3D, asynchronously, this results in “This API was accessed with arguments from the wrong context.” in a TargetInvocationException.

The 3D-content is generated from the data of a 3D-scanning device. The communication&calculations needed for that are done in a separate thread. First, I tried to acces the viewport3D from that thread. I realized this should be done by the GUI-thread, so now I use this code:

        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);

It seems that the object named “model” is not in the context of the current thread. How can I fix this? Is there a way to get the model to the context of the Dispatcher?
Or is this way of doing this just not the way to go here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:19:32+00:00Added an answer on May 18, 2026 at 12:19 pm

    This will occur when ever you generate/modify scene objects to add to Viewport, from a different thread then the one Viewport was instantiated on. There is a simple work around. Encapsulate the code that updates Viewport objects into a function. Insert the following snippet and you are done.

    private delegate void MyFunctionDelegate();
    
    void MyFunction()
    {
         if(!Application.Current.Dispatcher.CheckAccess())
         {
             Application.Current.Dispatcher.Invoke(new MyFunctionDelegate(MyFunction));
             return; // Important to leave the culprit thread
         }
         .
         .
         .
         this.Viewport3D.Children.Remove(model);
         MyModifyModel(model);
         this.Viewport3D.Children.Add(model); 
    }
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting this error when try to add an item to my repositories/context: Collection has
I try to add lookup field in content type. Field has this definition: <Field
I am new to this and when I try to add more than one
I'm using Google Maps API on my web page. I'm try to add multiple
i want to call a webpage from jQuery and add the content to it
My IDE crashes any time I try add a new component to the toolbar.
I try to add an addons system to my Windows.Net application using Reflection; but
I try to add dots between the page title and the page number in
I try to add Message.framework to my project frameworks directory. After that I compile
I try to add a class to a td-element using javascript with the internet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.