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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:00:54+00:00 2026-06-13T10:00:54+00:00

I am a bit new to threading (not new to C#, just haven’t done

  • 0

I am a bit new to threading (not new to C#, just haven’t done much threading). Can someone explain to me why this does not work?

I have a thread which calls a method I will call “Loop”. Loop contains a while loop which will continuously run, and on every loop of the while I want it to check if the A Key is down (using Microsoft’s Keyboard class within the XNA Framework). But for some reason it never registers that anything is being pressed.

static Thread thread = new Thread(Loop);
static bool abort = false;

public static void Begin()
{
    thread.Start();
}

private static void Loop()
{
    while (!abort)
    {
        if (Keyboard.GetState().IsKeyDown(Keys.A))
            Console.WriteLine("A pressed.");
    }
}

Might anyone know why the Console.WriteLine() is never being called?

EDIT:

I guess I should explain a little bit. What I am actually trying to do is create something similar to ActionScript’s events in C#. So I want to pass a “condition” and an “action” to call if that condition is met in this separate class which contains this thread. What this would do would allow me to just add “event listeners” to objects and it would automatically constantly check if one of the events gets triggered, rather than leave it to me to write If statements in code to check for the events.

Upon trying to do so, the first thing I tested was regarding this XNA Keyboard stuff, because it was one of the reasons I originally wanted to build this system, but it didn’t work. So I created the standalone code which i posted above to see if I had made an error in my previous code and it still didn’t work.

  • 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-13T10:00:55+00:00Added an answer on June 13, 2026 at 10:00 am

    I never use XNA so I didn’t really “know” but I’ve run into similar situations where you can’t get keyboard (and other) input from a worker thread. I googled and found that in XNA this does seem to be the case. See this for example

    So you need to (and probably want to) process your game input in the GUI thread. Just checking for input on each update tick should be fine. I doubt even if it did work, you would gain any performance – and you might introduce some interesting synchronization bugs 😉

    It does look like your creating your worker thread properly – this just isn’t an application for it.

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

Sidebar

Related Questions

I'm not the best with multi-threading, and this is a bit complicated, so hopefully
I'm a bit new to Rails/RSpec/Capybara, so this is probably a newbie question, but
I am a bit new to iOS Development and I was wondering if someone
I'm new to the idea of Threading, but not asynchronous behavior. My Android app
I am new with this stuff of Threading in Delphi. so, I am trying
Preface: This has become a quite a long post. While I'm not new to
I am a bit new in threading in c# and on general, in my
NOTE: I'm not saying this is a good idea, just trying to find out
I'm a bit new to linq and I'm unsure if what I desire is
I'm a bit new to wordpress plugin coding. I've been working on a plugin

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.