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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:06:52+00:00 2026-06-02T00:06:52+00:00

Context: the application I’m trying to make does not display a form initially, but

  • 0

Context: the application I’m trying to make does not display a form initially, but only an open file dialog. After selecting a file the application may exit or open a form.

I’m having trouble closing my application after calling Application.Run(). The following example does not produce an application that kills itself.

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        var context = new Context();
        Application.Run(context);
        Console.Beep();
    }
}

class Context : ApplicationContext
{
    public Context()
    {
        Application.Exit();
    }
}

On a side note, what preparations do I need to make before I can open a form? Do I need to have a call to Application.Run before I can show forms?

Thanks a bunch! XOXO

  • 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-02T00:06:53+00:00Added an answer on June 2, 2026 at 12:06 am

    You could try moving the exit logic to a new method:

    class Context : ApplicationContext 
    { 
      public void Exit() 
      { 
        Application.Exit(); 
      } 
    } 
    

    and have Application.Run call context.Exit() when needed

    The problem with the original approach is that you placed the exit logic in the constructor of Context, which means every time you create a Context object, you have the potential to exit your program (it is a certainty in the case of the code you posted). Instead have Context capture all relevant (context) information and make the decision to exit based on that info when an explicit method call is made after it was created.

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

Sidebar

Related Questions

I am trying to add some filtering to the application context file, which resides
I think singleton is only within one application context. If having multiple application context
I am trying to add a test spring application context to the java runtime,
Am trying to get the application context in my JSP page. I have the
In my spring application context file, I have something like: <util:map id="someMap" map-class="java.util.HashMap" key-type="java.lang.String"
Our project has two application contexts: application-context.xml application-context-test.xml Currently each file has duplicate bean
Is it possible to define a macro in my Spring application context XML file
I'm having the following problem. I created a application context file for spring.net. The
I am trying to extract the bean from application context. so I defined class:
I am trying to inject a JAXBContext into spring application context, by: <bean id=jaxbContext

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.