我有这个压缩视频任务,它使用外部程序在 c# 中完成。完成此压缩并写出文件需要一些时间。在我知道外部操作有时间完成之前,我不想运行下一段代码。
我想做一个简单的 Thread.sleep(一些猜测);然后运行下一行代码还是有更好的方法?
这就是我压缩视频的方式:
try
{
String finalCommand = "";
String thePath = System.IO.Path.GetDirectoryName(fileName);
finalCommand ="-i " + fileName + " -s 320x240 -b 300k -r 30 -f avi " + thePath + "\\C" + System.IO.Path.GetFileName(fileName);
System.Diagnostics.ProcessStartInfo ffmpegcmd = new System.Diagnostics.ProcessStartInfo(Application.StartupPath + "\\ffmpeg.exe",
"-i \"" + fileName + "\" -s 320x240 -b 300k -r 30 -f avi \"" + thePath + "\\C" + System.IO.Path.GetFileName(fileName) + "\"");
ffmpegcmd.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
System.Diagnostics.Process p = System.Diagnostics.Process.Start(ffmpegcmd);
LogUtil.writeLog("About to wait for FFMPEGCMD process");
p.WaitForExit();
success = true;
LogUtil.writeLog("FFMPEGCMD process exited perfectly!");
}
catch (Exception ex)
{
LogUtil.writeLog("ERROR compressing and using FFMPEG");
success = false;
}
虽然我意识到我不确定这是否是在自己做一个进程/线程嗯。