The work is done,why does Process.WaitForExit() still block the thread?
-
Hi everyone, I run into a tricky issue when I run cmd.exe using Process class in C#. 1)Here's the C# code,it run the specified .bat file in command-line: m_BasicDataProc = new Process(); m_BasicDataProc.StartInfo.FileName = "cmd.exe"; m_BasicDataProc.StartInfo.CreateNoWindow = false; m_BasicDataProc.StartInfo.UseShellExecute = false; m_BasicDataProc.StartInfo.RedirectStandardOutput = true; m_BasicDataProc.StartInfo.RedirectStandardInput = true; m_BasicDataProc.StartInfo.WorkingDirectory = Path.GetDirectoryName(batchFilePath); m_BasicDataProc.Start(); string batchFileName = Path.GetFileName(batchFilePath); string ipLine = batchFileName;StreamWriter inputStream = m_BasicDataProc.StandardInput; inputStream.WriteLine(ipLine); inputStream.Close(); m_BasicDataProc.WaitForExit(); m_BasicDataProc.EnableRaisingEvents = true; 2)In the .bat file,it calls a .vbs file with the content pretty much like this: option explicit dim fso Set fso = CreateObject("Scripting.FileSystemObject") Dim CreateFile Set CreateFile = fso.CreateTextFile("InstallScripts\CreateTriggers.sql", true) ...... CreateFile.writeLine(strStatement) CreateFile.WriteLine set CreateFile = nothing set fso = nothing // I found that the file CreateTriggers.sql was created successfully,it means that the work of this .bat file is finished,but it's really odd that the application is still blocked by the code line "m_BasicDataProc.WaitForExit();" and could not exit. Has anyone been in same situation? Anything you could help would be appreciated!
-
Hi everyone, I run into a tricky issue when I run cmd.exe using Process class in C#. 1)Here's the C# code,it run the specified .bat file in command-line: m_BasicDataProc = new Process(); m_BasicDataProc.StartInfo.FileName = "cmd.exe"; m_BasicDataProc.StartInfo.CreateNoWindow = false; m_BasicDataProc.StartInfo.UseShellExecute = false; m_BasicDataProc.StartInfo.RedirectStandardOutput = true; m_BasicDataProc.StartInfo.RedirectStandardInput = true; m_BasicDataProc.StartInfo.WorkingDirectory = Path.GetDirectoryName(batchFilePath); m_BasicDataProc.Start(); string batchFileName = Path.GetFileName(batchFilePath); string ipLine = batchFileName;StreamWriter inputStream = m_BasicDataProc.StandardInput; inputStream.WriteLine(ipLine); inputStream.Close(); m_BasicDataProc.WaitForExit(); m_BasicDataProc.EnableRaisingEvents = true; 2)In the .bat file,it calls a .vbs file with the content pretty much like this: option explicit dim fso Set fso = CreateObject("Scripting.FileSystemObject") Dim CreateFile Set CreateFile = fso.CreateTextFile("InstallScripts\CreateTriggers.sql", true) ...... CreateFile.writeLine(strStatement) CreateFile.WriteLine set CreateFile = nothing set fso = nothing // I found that the file CreateTriggers.sql was created successfully,it means that the work of this .bat file is finished,but it's really odd that the application is still blocked by the code line "m_BasicDataProc.WaitForExit();" and could not exit. Has anyone been in same situation? Anything you could help would be appreciated!