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

  • Home
  • SEARCH
  • 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 7076279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:16:45+00:00 2026-05-28T06:16:45+00:00

Possible Duplicate: WPF and cross thread operations I am having trouble with a window

  • 0

Possible Duplicate:
WPF and cross thread operations

I am having trouble with a window in my wpf application displaying, but not updating the view. When placing the cursor over the opened window the loading icon is shown and the window is unresponsive. I am thinking this is likely due to some threading issue I don’t have enough experience in seeing.


Here is the setup:

My main program runs on startup and creates and instance of a MainWindow window which implements a custom interface (IPlayer). The main program then runs a process which interracts with IPlayer to accomplish some task, the idea being that the main program requests actions from the MainWindow, which prompts the user for some sort of input and displays the results.

I’ll simplify the code for clarity. Assume this program simply runs a sort of chatter bot game.

class MainProgram
{

    [STAThread]
    static void main(string[] args)
    {
        MainWindow wdw = new MainWindw();
        Game g = new Game(wdw);

        wdw.Show();
        g.RunGame();
    }

}

class Game
{
    public IPlayer p;
    Game(IPlayer) { this.p = p; }

    public RunGame()
    {
        string r = GetResponse("How was your day?");

        ...
    }
}


public partial class Human_Player : Window, IPlayer
{
    public string GetResponse(string Question)
    {
        ShowQuestion(Question);
        string r = GetResponse();
        DisplayResponse(r);
        return r;
    }

    ...
}

I gave running RunGame() in a separate thread a shot like this:

Thread thread = new Thread(new ThreadStart(game.RunGame));
thread.Start(); 

but got an InvalidOperationException in response stating “The calling thread cannot access this object because a different thread owns it.”

Any help here would be appreciated since I’m pretty new to this stuff. Thanks ahead of time!


EDIT:

Just to clarify, I’m not creating any new threads at the moment. Thus I don’t think I’m doing any multi-threading. I’m attempting to run game.RunGame() on the main thread after opening the window. The runGame method consists of a large loop which calls a method on the Human_Player window that changes the UI.

As far as I know there are only two threads:
– Main Thread – MainProgram and Game run here. I think the windows runs here as well but I could be wrong… please clarify
– Rendering Thread – the UI is rendered 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-28T06:16:46+00:00Added an answer on May 28, 2026 at 6:16 am

    Argh, this question is asked soooo many times… You cannot update a GUI control from a different thread than the Dispatcher thread associated to the control. You will need to run your update code using Dispatcher.BeginInvoke to update the GUI from the correct thread.

    If you are not running the code from a different thread then it’s possible that your method is taking too long to execute, thus causing the GUI to hang because the event thread is blocked from accepting user input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is the difference between WPF and Silverlight application? What are the
Possible Duplicate: WPF: XAML property declarations not being set via Setters? I am stuck
Possible Duplicate: WPF MessageBox window style For some reason the MessageBox that comes with
Possible Duplicate: How can a WPF application be launched before I logon to Windows?
Possible Duplicate: How can one host Flash content in a WPF application and use
Possible Duplicate: In WPF, what are the differences between the x:Name and Name attributes?
Possible Duplicate: What WPF books would you recommend? GUI's written using WPF seem to
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Drag WPF Popup control I created a WPF popup control in my
Possible Duplicate: WPF Button isPressed and isEnabled problem Here is a snippet of code

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.