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

The Archive Base Latest Questions

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

I am writing an application that has both CLI and GUI. I read most

  • 0

I am writing an application that has both CLI and GUI.

I read most questions and articles regarding it, and found highly usefull this question:

Can one executable be both a console and GUI application?

My final code looks like:

        if (args.Length > 0)
        {
            //console code            
        }
        else
        {
            FreeConsole();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form());
        } 

This works great when running the .exe by double click, or when debugging, or from console with arguments.

However, when running it from the console with no arguments, the GUI is opened, like I intended, but the console is stuck waiting for the GUI to close.

This is uncharacteristic GUI and console behavior. the console usually launch the GUI and not wait to its exit, but for new commands.

Is there is a way to avoid it?

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

    The accepted answer in the question you linked to contains this passage:

    Junfeng’s second technique is what ildasm uses. He quotes the process
    that ildasm’s author went through when making it run in both modes.
    Ultimately, here’s what the it does:

    The program is marked as a console-mode binary, so it always starts
    out with a console. This allows input and output redirection to work
    as normal. If the program has no console-mode command-line parameters,
    it re-launches itself. It’s not enough to simply call FreeConsole to
    make the first instance cease to be a console program. That’s because
    the process that started the program, cmd.exe, “knows” that it started
    a console-mode program and is waiting for the program to stop running.
    Calling FreeConsole would make ildasm stop using the console, but it
    wouldn’t make the parent process start using the console.

    To me it looks like the headache of having a binary trying to switch between the console subsystem and GUI subsystem (which really isn’t allowed) is more effort than it’s worth.

    One approach would be to have a separate GUI application .exe. Whenever the console app is started without parameters it launches the GUI app and closes itself.

    To prevent code duplication this probably requires all the actual logic of the application to be put in a separate class library.

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

Sidebar

Related Questions

I work on an application that has a both a GUI (graphical) and API
Im writing a WPF application that has a zoom and pan ability, but what
I'm writing an application which has two classes that provide basically the same functionality
I am writing a small WebSocket server application that should support both draft 17
I'm writing a sample application that is both GDI and WPF. I have a
I'm writing a little web application that has two things in it : At
I'm writing an application that needs to work on both mysql and postgresql. I
I am writing an application in Eclipse, that has a servlet, and an android
I'm currently writing an application that has a NotifyIcon and I'm trying to figure
im writing an application that downloads and installs addons for programs which needs to

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.