大家好我试图通过创建进程来执行gs命令,我希望它等到进程完成。我使用了waitforexit(),但它超越了waitforexit()。
public async void pdf2Png(string name, string pdf, int lastPage)
{
Stopwatch stopwatch = Stopwatch.StartNew();
Response.Write((stopwatch.ElapsedMilliseconds / 1000) + " pdf 2 png" + "<br>");
Process obj_process = null;
ProcessStartInfo obj_startinfo = null;
StreamWriter obj_writer = null;
string sOutputFile = Path.Combine(Path.GetDirectoryName(pdf), name + "%d.png"); ;
string inputFilePath = pdf;
int lP = lastPage;
Response.Write(sOutputFile + " : " + inputFilePath + "<br>");
string str_command = string.Format("gswin64 -dSAFER -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=\"{0}\" -sDEVICE=png16m -r600 -sOutputFile=\"{1}\" \"{2}\"",
lP, sOutputFile, inputFilePath);
obj_startinfo = new ProcessStartInfo("cmd.exe");
obj_startinfo.UseShellExecute = false;
obj_startinfo.RedirectStandardInput = true;
obj_startinfo.RedirectStandardError = true;
obj_startinfo.RedirectStandardOutput = true;
obj_startinfo.CreateNoWindow = true;
obj_startinfo.ErrorDialog = false;
obj_startinfo.WindowStyle = ProcessWindowStyle.Hidden;
obj_process = Process.Start(obj_startinfo);
obj_writer = obj_process.StandardInput;
obj_writer.WriteLine(str_command);
obj_writer.Flush();
obj_writer.Close();
obj_writer.Dispose();
obj_writer = null;
obj_process.WaitForExit();
System.IO.File.WriteAllText(@"D:\shits not working.txt", str_command);
stopwatch.Stop();
Response.Write((stopwatch.ElapsedMilliseconds / 1000) + " pdf 2 png" + "<br>");
}
以下一行&#34; Waitforexit()&#34;甚至在创建png之前就会执行并退出进程。我能做什么?