在synlock中执行批处理文件以等待其内部过程在vb.net中完成

时间:2018-12-04 14:22:52

标签: vb.net batch-file

我需要在vb.Net中的模块中执行批处理文件,但是问题是我执行相同的操作,并且如果完成,则程序不执行下一步。

如果执行下一步,则由于创建文本文件而导致我的过程中断,下一步是在数据库mysql中上载。

我尝试在synlcok中执行,并且没有任何区别,如何使用synlock来完成批处理文件的执行。

我的代码是:

Dim myLock As Object

synlock myLock
    Dim pProces As Process = Process.Start(psi)
End synlock

delay(350)

PS:延迟是重命名为线程等待,该过程在等待中继续,但是我需要知道何时完成执行批处理文件。

1 个答案:

答案 0 :(得分:-1)

如果我完全理解您的问题,那么您要等待批处理文件执行完毕,然后再转到代码的下一部分。

您可以使用process.HasExited等待该过程完成。

Dim pProces As Process = Process.Start(psi)

While Not pProces.HasExited
    System.Windows.Forms.Application.DoEvents ' if this is a windows form or console app
End While

If pProces.ExitCode = 0 Then
    ' Continue your next step here
Else
    ' Error occured while running the batch file 
End If

OR

您可以使用Process.Exited事件。