Thursday, June 2, 2016

Hide Console Window in C# Console Application

Solution 1:

Change the output type from Console Application to Windows Application. This can be done under Project -> Properties -> Application in Visual Studio



Solution 2:

If you are using the ProcessStartInfo class you can set the window style to hidden:

System.Diagnostics.ProcessStartInfo start =
      new System.Diagnostics.ProcessStartInfo();     
start.FileName = dir + @"\Myprocesstostart.exe";
start.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

Solution 3:

If you are using Process Class then you can write:

yourprocess.StartInfo.UseShellExecute = false;
yourprocess.StartInfo.CreateNoWindow = true;

before yourprocess.start(); and process will be hidden.

Reference:

http://stackoverflow.com/questions/836427/how-to-run-a-c-sharp-console-application-with-the-console-hidden

No comments: