简体   繁体   English

如何在c#中的控制台应用程序中在后台运行程序

[英]How can I make a program run in the background from a console application in c#

Hi there I am currently working on a Console Application that run's a .bat file and when the program starts it pops up as the main box on my window and as this is running several times a min, this can get a little annoying is there any way when I run this command... 大家好,我目前正在开发一个运行一个.bat文件的控制台应用程序,当程序启动时,它会弹出窗口上的主框,并且因为它运行了几分钟,这有点烦人有没有我运行这个命令的方式......

System.Diagnostics.Process.Start(@"newmessage1.bat");

is there a way of making the .bat cmd window running in a kinda hidden state? 有没有办法让.bat cmd窗口以某种隐藏状态运行?

You could play around a little with the CreateNoWindow and UseShellExecute properties: 你可以使用CreateNoWindowUseShellExecute属性玩一下:

var psi = new ProcessStartInfo
{
    FileName = "newmessage1.bat",
    CreateNoWindow = true,
    UseShellExecute = false
};
Process.Start(psi);

Use the ProcessStartInfo.CreateNoWindow property. 使用ProcessStartInfo.CreateNoWindow属性。

Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.StartInfo.FileName = @"newmessage1.bat";
myProcess.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM