每个循环的process.start问题 [英] process.start problem in for each loop
问题描述
在通过按钮单击代码调用命令行应用程序时,我陷入了困境.
该应用程序为ffmpeg.
我的应用程序是将pdf文档转换为图像到电影文件.
我首先创建一个用于复制图像的临时目录,然后使用输入(文件夹),输出-文件名
的参数调用ffmpeg
我使用每个循环来访问在列表框中输入的不同目录.然后为每个目录调用ffmpeg.exe.
现在出现了问题,我为列表框中的每个目录创建了一个bmp文件夹
然后我打电话给ffmpeg,将图像转换为电影,然后删除文件夹.我想要的是仅在进程退出时才删除该文件夹,因为该文件夹在中途被删除并且并非所有图像都被转换.
如何知道转换完成后何时退出流程?
I am stuck in a problem in calling a command-line application through a button-click code.
the application is ffmpeg.
my application is to convert pdf docs to images to movie files.
I first create a temp directory for copying images, and then call ffmpeg with the arguments of input (folder), output - file name
i use for each loop for accessing different directories entered in a listbox. then for each directory i call ffmpeg.exe.
now comes the problem, for each directory in listbox i create a bmp folder
then i call ffmpeg , convert the images to movie, and delete the folder. What i want is the folder to be deleted only when the process has exited, because the folder gets deleted in midway and not all the images are converted.
How do i know when the process has exited after completing the conversion?
Dim pathmviasf As String = "c:\Aio-Pdf-Batch\Movies\Asf\"
Dim pathmvitmp As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\Bmp\"
For cnt As Integer = 0 To ListBoxControl1.Items.Count - 1
If Directory.Exists(pathmvitmp) Then
Directory.Delete(pathmvitmp, True)
Directory.CreateDirectory(pathmvitmp)
Else
Directory.CreateDirectory(pathmvitmp)
End If
Dim i As Integer
pdffile1 = PDFFile.Open(ListBoxControl1.Items(cnt))
For i = 0 To pdffile1.PageCount - 1
Dim pageImage As Bitmap = pdffile1.GetPageImage(i, 96)
pageImage.Save(String.Format(pathmvitmp & "page{0}.bmp", i), ImageFormat.Bmp)
Next i
strfil = pathmviasf & IO.Path.GetFileNameWithoutExtension(ListBoxControl1.Items(cnt)) & "\"
If Not Directory.Exists(strfil) Then
Directory.CreateDirectory(strfil)
Else
Directory.Delete(strfil, True)
Directory.CreateDirectory(strfil)
End If
Dim videoPath As String = strfil & IO.Path.GetFileNameWithoutExtension(ListBoxControl1.Items(cnt)) & ".asf"
Dim ffmpeg As Process = New Process()
ffmpeg.StartInfo.RedirectStandardOutput = True
ffmpeg.StartInfo.UseShellExecute = False
ffmpeg.StartInfo.Arguments = String.Format(videoPath & " " & 0.5)
ffmpeg.StartInfo.FileName = "ffmpeg.exe"
ffmpeg.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
ffmpeg.Start()
Next
推荐答案
Start方法返回该过程的句柄,然后可以等待
The Start method returns a handle to the process, you can then wait for it to end.
,您可以在ffmPeg Process对象上使用WaitForExit()方法
http://msdn.microsoft.com/zh-我们/library/system.diagnostics.process.waitforexit%28VS.71%29.aspx [
you could use the WaitForExit() method on the ffmPeg Process object
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.waitforexit%28VS.71%29.aspx[^]
Given WaitForExit() can be an indefinite wait, I''d make sure to add a kill button to your code and use the Kill() method, so they can kill it if they get bored.
这篇关于每个循环的process.start问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!