1

我正在尝试构建一个“加载器” - 意思是一个程序,当我运行它时会启动一些预定义的程序。问题是我不希望启动的程序中断我的工作流程,并且每个程序都有 0-2 秒的“挂起”

            If showLog = True Then Console.WriteLine("Starting --->" + "Skype")
            proc.StartInfo.FileName = "C:\Program Files (x86)\Skype\Phone\Skype.exe"
            proc.StartInfo.Arguments = "/nosplash /minimized"
            proc.Start()
            proc.PriorityClass = ProcessPriorityClass.BelowNormal

我认为我可能能够以"Idle" 或 "BelowNormal" 优先级启动该过程。但我只能在程序加载后设置该优先级 - 这为时已晚

任何想法?

请注意,一切正常,但问题是“冻结”持续时间很短- 当加载的程序过多时,这变得很重要。

谢谢。

4

2 回答 2

0

感谢Mike Drucker,我做到了:

(ProcessName = 没有“.exe”的执行文件名 - “skype.exe” ===> “skype”)

Private Sub StartProcessAndNormalize(Path As String, ProcessName As String, Optional Args As String = "", Optional PrintLog As Boolean = False)
    If PrintLog = True Then Console.WriteLine("Starting --->" + ProcessName)
    StartCmdProcess(Path, Args, ProcessName)
    ProcessBackToNormal(ProcessName)
End Sub

Private Sub ProcessBackToNormal(ProcessName As String)
    Dim proc As Process
    Threading.Thread.Sleep(2000)
    proc = (From p In System.Diagnostics.Process.GetProcessesByName(ProcessName) Order By p.StartTime Descending).FirstOrDefault()
    Try
        proc.PriorityClass = ProcessPriorityClass.Normal
    Catch
        Console.WriteLine("Can't find process " & ProcessName)
    End Try

End Sub

Private Sub StartCmdProcess(Path As String, Args As String, Optional ProcessName As String = "")
    Dim proc As Process = New Process
    proc.StartInfo.FileName = "cmd.exe"
    proc.StartInfo.Arguments = "/c   start """ & ProcessName & """ /BelowNormal """ & Path & """ " & Args
    proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
    proc.Start()
    proc.WaitForExit()
End Sub

我们像这样使用它:

StartProcessAndNormalize("C:\Program Files (x86)\Skype\Phone\Skype.exe", "Skype", "/nosplash /minimized", showLog)
于 2013-09-20T23:36:49.680 回答
0

一种选择是使用 cmd /c start /low executable.exe 参数启动 Skype,这将在 skype.exe 启动后完成,然后您可以按名称检索新的 Skype.exe 进程。

proc.StartInfo.FileName = "cmd.exe"
proc.StartInfo.Arguments = "/c start /low ""C:\Program Files (x86)\Skype\Phone\Skype.exe"" /nosplash /minimized"
proc.Start()
proc.WaitForExit()
proc = (From p In System.Diagnostics.Process.GetProcessesByName("skype.exe") Order By p.StartTime Descending).FirstOrDefault()

`

于 2013-09-20T16:09:28.683 回答