小编tec*_*chy的帖子

C# 控制台应用程序将进程置于前台

使用以下 C# 控制台应用程序代码,我可以使用 Jenkins 在后台运行该进程。但现在我想在前台看到这个过程。我在这里做错了什么?

[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr handle);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool IsIconic(IntPtr handle);

private void startT32app()
{
    IntPtr handle;
    try
    {
        Console.WriteLine("T32 launching");
        string path = @"C:\T32\bin\windows64\t32mppc.exe";
        string args = @"C:\T32\config.t32";
        ProcessStartInfo procInfo = new ProcessStartInfo(path, args);
        procInfo.CreateNoWindow = false;
        procInfo.UseShellExecute = true;
        procInfo.WindowStyle = ProcessWindowStyle.Normal;

        Process procRun = Process.Start(procInfo);
        handle = procRun.MainWindowHandle;
        SetForegroundWindow(handle);
    }
    catch
    {
        Console.WriteLine("Failed to launch T32");
    }
}
static void …
Run Code Online (Sandbox Code Playgroud)

c# console-application c#-4.0

3
推荐指数
1
解决办法
3177
查看次数

标签 统计

c# ×1

c#-4.0 ×1

console-application ×1