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 8650409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:48:50+00:00 2026-06-12T13:48:50+00:00

I am trying to make a simple game in C#/XAML. I have a worker

  • 0

I am trying to make a simple game in C#/XAML. I have a worker thread which calculates the new positions of the game elements each tick and then updates the UI with new positions. Or at least it should be.

Instead, the output says:

A first chance exception of type 'System.Exception' occurred in Game.exe
An exception of type 'System.Exception' occurred in Game.exe but was not handled in user code
The thread '<No Name>' (0x1218) has exited with code 0 (0x0).

I’ve sifted through this with break points, and the code breaks in this area.

        //Stop previous animation in case it is ongoing
        GameStoryboard.Stop();

        //Remove all previous timelines from the storyboard
        foreach (Timeline timeline in GameStoryboard.Children)
        {
            GameStoryboard.Children.Remove(timeline); 
        }

The first line of code there crashes it, but I can comment out the GameStoryboard.Stop() line (it’s only relevant in case the game’s tick time is automatically lowered between loops), and then it just crashes on the foreach loop instead. If I comment out the foreach loop, it crashes on the next time I reference GameStoryboard.

The declaration for GameStoryboard looks like this:

        <Canvas Name="GameCanvas" Height="900" Width="1440" Background="Blue">
            <Canvas.Resources>
                <Storyboard x:Name="GameStoryboard"/>
            </Canvas.Resources>
        </Canvas>

The only theory I can think of is, do XAML objects not let you reference them from a different thread than the one which initialized it? If so, what’s the best way to do what I’m trying to? And if not, anyone have any idea what could be causing this?

  • 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-06-12T13:48:51+00:00Added an answer on June 12, 2026 at 1:48 pm

    As Alex said, you can only access DependencyObjects from the thread that created them.

    You can use the Dispatcher to execute your code on the UI thread to access your ‘StoryBoard’. For example if you were using a BackgroundWorker in your code-behind:

    private void BwOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs)
    {
        Dispatcher.BeginInvoke(new Action(ClearChildren), DispatcherPriority.Normal);
    }
    
    private void ClearChildren()
    {
        GameStoryBoard.Children.Clear();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to make a very simple game where i have 7 positions
Trying to make simple minesweeper game in python, but have one problem. I have
I am fairly new to iOS development and trying make a simple app which
I have just started trying to make a simple game with XNA 3.1 to
For quite awhile I have been trying to make a simple game in Java
I have a simple question, I'm trying to make an huge game for Windows
I'm trying to make a simple Windows Store game in C# and XAML, one
I am trying to make a simple pong game using opengl-es. I have checked
I'm trying to make a very simple game. In it I have objects (
I'm trying to make a simple windows 8 metro game using c# and xaml.

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.