保持Process.Start()同时运行

时间:2018-04-05 18:24:01

标签: vb.net

我遇到了问题,我正在复制文件,然后使用cmd中的“pdftk”将它们组合成pdf文件。

我将复制过程放入嵌套循环中以获取我想要的文件。但是,组合过程在复制过程运行的同时开始,该过程组合了已复制的任何文件。它应该等到复制完成然后启动组合。请帮帮我这个

Private Sub PDF_Print(ProcessDir As String)

 Dim i As Integer = 0
 For i = 1 To CInt(txtNumofSet.Text)

Dim Labelcopy As String = "/c S: & cd ""S:\User Files\Shipping & Receiving\NewlyWeds labels\process"" & for /l %x in (1, 1, " & txtCopies.Text & ")" &
                                  "do (copy """ & SourceFile & """ workarea\" & i & "S" & "%x.pdf)"
        Dim Run = Process.Start("cmd.exe", Labelcopy)

        Dim Blankcopy As String = "/c S: & cd ""S:\User Files\Shipping & Receiving\NewlyWeds labels\process"" & for /l %x in (1, 1, " & txtNumofblanks.Text & ")" &
                                  "do (copy """ & ProcessDir & """ workarea\" & i & "SB" & "%x.pdf)"
        Dim Run1 = Process.Start("cmd.exe", Blankcopy)

    Next


    Process.Start("S:\User Files\Shipping & Receiving\NewlyWeds labels\process\Label.cmd")


    ' Me.Close()
End Sub

有没有办法告诉最后一个Process.start在前两个完成运行后启动。谢谢。

2 个答案:

答案 0 :(得分:0)

您应该使用.NET框架来复制文件,例如File.Copy

答案 1 :(得分:0)

可以使用Process.HasExited Property查看流程是否已完成。这是一个简单的例子:

Dim objProcess As Process = Process.Start("cmd.exe", Labelcopy)

Do Until objProcess.HasExited

    System.Threading.Thread.Sleep(100)

Loop

Process.Start("S:\User Files\Shipping & Receiving\NewlyWeds labels\process\Label.cmd")