Search code examples
c#console

Using AttachConsole, user must hit enter to get regular command line


I have a progaram that can be ran both as a winform, or from command line. If it is invoked from a command line I call AttachConsole(-1) to attach to parent console.

However, after my program ends, the user must hit enter to get back the standard command prompt ("c:\>"). is there a way to avoid that need?

Thanks. I could wrap it in a cmd file to avoid that issue, but I would like to do it from my exe.


Solution

  • Try adding this line just before your exe exits...

    System.Windows.Forms.SendKeys.SendWait("{ENTER}");
    

    Bit of a hack, but best I could find when I encountered that problem.