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

The Archive Base Latest Questions

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

I’m working on writing a splash screen that returns a game mode (int) and

  • 0

I’m working on writing a splash screen that returns a game mode (int) and an IP address (string). The idea is the splash screen runs, takes user input and then runs the main game with these options. I’m using a thread to achieve this – the thread polls for an exit request from the splash screen, then pulls the values out to program.cs and calls exit() on splash.

The main game runs on it’s own with no issues but with the splash screen enabled the game runs just 1 frame and seems to be disposed of by garbage collection after running the update method. (returns a DisposedObjectException or something of the sort if trying to reference it) After a bit of debugging I’ve found the issue is with the exit command. Code is as follows:

using System;
using System.Threading;

namespace SplashScreen
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            int choice = 0;
            string ip = "";
            bool runSplash = true;
            bool useThreading = true;
            bool ignoreThreadResponse = false;
            // Debug option, toggle running splash screen
            if (runSplash == true)
            {
                bool splashrunning = true;
                using (Splash1 splash = new Splash1())
                {
                    if (useThreading)
                    {
                        // Run a thread to poll whether the splash screen has requested an exit every 0.5 seconds
                        Thread t = new Thread(() =>
                        {
                            while (splashrunning)
                            {
                                // If splash requests exit pull gameMode choice and IP Address before killing it, then quit this thread
                                if (splash.requestingExit)
                                {
                                    choice = splash.choice;
                                    ip = splash.ip;
                                    // The offending piece of code, without this you can simply select an option, force close and second part runs fine
                                    //splash.Exit();
                                    splashrunning = false;
                                }
                                Thread.Sleep(500);
                            }
                        });
                        t.Start();
                    }
                    splash.Run();
                }
            }
            // If splash screen is not running, assign default values
            if(!useThreading || !runSplash || ignoreThreadResponse)
            {
                choice = 2;
                ip = "127.0.0.1";
            }
            if (choice != 0)
            {
                // This game is picked up by garbage collection after running Update once
                using (Game1 game = new Game1(choice, ip))
                {
                    game.Run();
                }
            }
        }
    }
}

When splash.Exit() is called, it causes game1 to be collected after the first update. If I disable threading it works fine. If I exit using the X at the top right it works fine. Whether or not I ignore the thread response the game fails to run if threading is enabled and I call splash.Exit().

What I’m looking for is any of the following:

  • A reason why the second game is being collected.

  • An alternative way to exit a game or call the ‘close window’ (big red x) function.

  • A better way of implementing this.

I’ve used console input to do this in the past, but I want to move on to using a graphical interface instead of an ugly command prompt for the user.

Edit:
Turns out I was almost there. While GSM is probably the correct way of doing things, for anyone who just wants to grab the code from the question and throw caution to the wind you simply need to add a thread to run the second game.
I’m pretty sure this isn’t ideal, but it’s a lot less tweaking in my case.

Thread gt = new Thread(() =>
{
    using (Game1 game = new Game1(choice, ip))
    {
        game.Run();
    }
});
gt.Start();

So while I’d recommend anyone starting from scratch to use GSM, this might be a quick solution for someone else just trying to get it running.

  • 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-31T06:45:27+00:00Added an answer on May 31, 2026 at 6:45 am

    What does your Splash class look like? Exit is a method of the Game class, and exits the game. Is your Splash class inheriting Game? If so, it shouldn’t.

    Edit:

    After reading the bottom half of your post a bit more clearly – you should only have a single class that inherits from Game, and it should run your game. If you want to display a splash screen it should be a custom class, or look into the Game State Management sample.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And

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.