【问题标题】:Shelling out to a program without it appearing在没有出现的情况下退出程序
【发布时间】:2016-04-08 12:34:42
【问题描述】:

我怎样才能在 VB.NET/C# 中打开一个 DOS 应用程序并且它不会在屏幕上闪烁。我宁愿它不会出现,因为它会闪烁,它会打开,然后在完成处理后终止。

【问题讨论】:

标签: c#


【解决方案1】:

我发现这很有用example。引用如下:

static void LaunchCommandLineApp()
{
    // For the example.
    const string ex1 = "C:\\";
    const string ex2 = "C:\\Dir";

    // Use ProcessStartInfo class.
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.FileName = "dcm2jpg.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;

    try
    {
        // Start the process with the info we specified.
        // Call WaitForExit and then the using-statement will close.
        using (Process exeProcess = Process.Start(startInfo))
        {
            exeProcess.WaitForExit();
        }
    }
    catch
    {
        // Log error?
    }
}

【讨论】:

  • 不应该是startInfo.CreateNoWindow = false;true
  • 似乎ProcessWindowStyle.Hidden; 做了同样的事情。某些应用程序可能希望某个窗口存在于某处……我建议您操作这些设置,直到它以您希望的确切方式工作。我的回答只是为了提供一种访问流程设置的方法。
  • 太棒了,WindowStyle 修复了它。出现问题时不再难以停止应用程序 :) 问候 MiscellaneousUser 又名 Agent 005
猜你喜欢
  • 1970-01-01
  • 2021-07-26
  • 2011-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多