Process.Start slow when spawning more new processes

眉间皱痕 提交于 2019-12-23 05:36:12

问题


Processes launched via Process.Start seems to have around a 26-second delay when the spawned process (the "child") launches more new processes (the "grandchildren") - I'm trying to find a way to solve this issue. Specifically, this is occurring when the original process (the "parent") is an ASP.Net website or a Windows Service (tried both).

We're attempting to run a server-side command-line tool to gather information, make modifications in the file system, and continue with other processes when the "child" is finished. When creating the "child" directly via command-line, there is no delay, and with certain command-line parameters, the "child" does not spawn new processes, and there is no delay. However, with other parameters, the "child" spawns "grandchildren" (the same executable as itself, but we can't modify its code) and seems to have a 25-30 second (usually 26 seconds) delay before the first process is started, and then runs normally.

I've tried modifying the UseShellExecute property, the CreateNoWindow property, and the WindowStyle property, to no effect. ErrorDialog and the RedirectStandard* properties are false.

The code I'm using is as follows:

using (Process p = new Process())
{
    p.StartInfo = new ProcessStartInfo(exePath, args)
    {
        WorkingDirectory = workingDirectory,
        UseShellExecute = true,
        CreateNoWindow = true,
    };
    p.Start();
    p.WaitForExit();
}

Oh, I don't think it matters as I've seen the issue referenced elsewhere (but no solutions), but the exePath I'm using points to msysgit's git.exe.


回答1:


Hard to tell a reason why this might happen, you need to do further troubleshooting.

I would suggest that you use Process Explorer and Process Monitor to look for potential problems.

I would guess that the problem is not directly in your code but more related to the environment of the user. For example, the w3wp.exe process runs in a non-GUI session (session 0) and the user might not be configured to have web access (proxy configuration) so that you might see a timeout issue here.




回答2:


I had this same exact problem executing a .bat file which in turn made a call to git.cmd using Process.Start from a windows service. The git command would execute immediately if the .bat file was ran directly from the command line, but would delay exactly 50 seconds any time it was called from the windows service.

It came down to a permissions issue. After configuring my windows service to run as a user (administrator in my case), the git process ran immediately. You can probably modify your service installer to run the service as "User", but you can just modify the service properties after it's installed to the same effect.

There may be ways to enable "Local Service" to get around the delay, but I wouldn't know how.



来源:https://stackoverflow.com/questions/3513830/process-start-slow-when-spawning-more-new-processes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!