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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:56:57+00:00 2026-05-27T04:56:57+00:00

In my XNA game, I’ve got the game window and the console which is

  • 0

In my XNA game, I’ve got the game window and the console which is running a threaded Console.ReadLine() so the game doesn’t hang while waiting for scripting input. I’m trying to get it where when the game window closes, the Console closes automatically, as well as the input to actually work (with the ability to print things out whilst waiting on input).
I’ve gotten it to close automatically now by using code from this question: How to add a Timeout to Console.ReadLine()?

However, when I press enter to the input, an ObjectDisposedException is thrown. Also, I’m stuck with using a timeout when I’d rather the thing be instant. How would I go about fixing this?

public class ConsoleInput
{
    public bool running = true;

    public void Run()
    {
        String input;
        while (running)
        {
            input = ReadLine(500);
            //stuff
        }
    }

    string ReadLine(int timeoutms)
    {
        ReadLineDelegate d = Console.ReadLine;
        IAsyncResult result = d.BeginInvoke(null, null);
        result.AsyncWaitHandle.WaitOne(timeoutms);//timeout e.g. 15000 for 15 secs
        if (result.IsCompleted)
        {
            string resultstr = d.EndInvoke(result);
            Console.WriteLine("Read: " + resultstr);
            return resultstr;
        }
        result.AsyncWaitHandle.Dispose();
        return "";
    }

    delegate string ReadLineDelegate();
}

Which is called by:

LuaInput = new ConsoleInput();
LuaInputThread = new Thread(new ThreadStart(LuaInput.Run));
LuaInputThread.Start();

Thanks!

  • 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-27T04:56:58+00:00Added an answer on May 27, 2026 at 4:56 am

    Have you tried setting the thread’s

    IsBackground = true; ? This will force it closed and will not allow the thread to block.

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

Sidebar

Related Questions

I'm making an XNA game console which should draw the output lines as they
For some reason the XNA Game Studio doesn't work on my PC. :( .
I want to make the XNA game window be in windowed mode but always
I'm trying to host an XNA game inside a WPF window using the Windows
I'm building a content editor for an XNA game and I've got my Content
I'm Trying to hide my XNA game window but i don't seem to be
I'm wondering if I can start Internet Explorer from my XNA game running on
I'm writing an XNA game where I do per-pixel collision checks. The loop which
I have dabbled in the Microsoft XNA game development framework which seems quite good
I am designing a gui system for my XNA game. The window can be

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.