c# - WPF Console app doesnt return to prompt once finished -


i have wpf app that, when command line arguments passed, runs command line app. show / acquire command line window use following code.

when run app works expected. if write out console during app app doesnt auto exit console, have press "enter" or invoke kind of readline - note not using readline in app @ all. in fact can make behaviour happen using simple code. how can prevent requirement "press enter" once app has run?

public static void main(string[] args) {     if (args.length == 0)     {         app app = new app();         app.run(new mainwindow());     }     else     {         // attach parent process console         if (!nativemethods.attachconsole(-1))         {             // allocate new console             nativemethods.allocconsole();         }          console.writeline("hey");          nativemethods.freeconsole();     } } 

i using following methods alloc / attach / free. note per rohit's suggestion have tried freeconsole directly after writeline still doesnt help

[dllimport("kernel32.dll")] private static extern bool allocconsole();  [dllimport("kernel32.dll")] private static extern bool attachconsole(int pid);  [dllimport("kernel32.dll", setlasterror = true)] private static extern int freeconsole(); 

after modal main window has completed, cleanup application resources using code similar following:

    [stathread()]     internal static void main()     {         // [your startup code here]          application app = new application();         app.dispatcherunhandledexception += dispatcherunhandledexception;         app.mainwindow = new mainwindow();         app.mainwindow.showdialog();          console.writeline("terminating...");         startup.freeconsole();          // http://msdn.microsoft.com/en-us/library/ms597014(v=vs.110).aspx         app.shutdown(0);      // <-- or application.current.shutdown(0);          // http://msdn.microsoft.com/en-us/library/system.environment.exit.aspx         environment.exit(0);  // <-- bit redundant     } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -