以下代码遍历文件夹下子文件夹下的PDF文档调用FLASHPAPER进程,为什么在运行到p.WaitForExit();
时不会等待进程运行结束后就继续往下执行代码?
foreach (FileSystemInfo fsinfo in fsinfos)//遍历子文件夹
{
string full_name = fsinfo.FullName.ToString();
string d_name = fsinfo.Name.ToString();
string Path_Pdf = full_name + "\\" + d_name + ".pdf";
string Out_Path = full_name + "\\" + d_name + ".swf";
if (!File.Exists(Path_Pdf))//如果不存在pdf文件
{
}
else
{
Process p = new Process()
p.StartInfo.FileName = @"c:\FlashPaper\FlashPrinter.exe";
p.StartInfo.Arguments = string.Format("{0} -o {1}", Path_Pdf , Out_Path );
p.Start();
p.WaitForExit();
p.Close();
p.Dispose();
}
}
MessageBox.Show("转换完毕");
时不会等待进程运行结束后就继续往下执行代码?
foreach (FileSystemInfo fsinfo in fsinfos)//遍历子文件夹
{
string full_name = fsinfo.FullName.ToString();
string d_name = fsinfo.Name.ToString();
string Path_Pdf = full_name + "\\" + d_name + ".pdf";
string Out_Path = full_name + "\\" + d_name + ".swf";
if (!File.Exists(Path_Pdf))//如果不存在pdf文件
{
}
else
{
Process p = new Process()
p.StartInfo.FileName = @"c:\FlashPaper\FlashPrinter.exe";
p.StartInfo.Arguments = string.Format("{0} -o {1}", Path_Pdf , Out_Path );
p.Start();
p.WaitForExit();
p.Close();
p.Dispose();
}
}
MessageBox.Show("转换完毕");
p.WaitForExit();
p.Close();中间插入 Thread.Sleep(100); 试试
Thread.Sleep(100);
p.WaitForExit();
p.Close();
还是不行
string ffmpeg = System.Web.HttpContext.Current.Server.MapPath("~/Content/ffmpeg/") + "ffmpeg.exe";
string ExportName = System.Web.HttpContext.Current.Server.MapPath(filePath + FileType + "/" + thisDate.ToString().Replace(" ", "") + "/") + randomDateTime + ".jpg";
string Command = ffmpeg + " -i " + FromName + " -y -s 640*480 -ss 00:00:02 -vframes 1 -an -sameq -f mjpeg " + ExportName;
log.Debug("command is :" + Command);
uploadFile.PreviewImage = ConfigurationSettings.AppSettings["WebSiteUrl"] + filePath.Replace("~", "") + FileType + "/" + thisDate.ToString().Replace(" ", "") + "/" + randomDateTime + ".jpg";
//System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.WorkingDirectory = System.Web.HttpContext.Current.Server.MapPath(filePath) + FileType + "/" + thisDate.ToString().Replace(" ", "");
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
//开始执行
p.Start();
p.StandardInput.WriteLine(Command);
p.StandardInput.WriteLine("Exit");
p.WaitForExit();
p.Close();
p.Dispose();
p.WaitForExit();
Thread.Sleep(100);
p.Close();
在中间,不是在前面