因此,我有这段代码来调用批处理文件。
If System.IO.File.Exists(FSourceFile) Then
Dim psi As New ProcessStartInfo(batchFileLoc + batchFileName)
psi.RedirectStandardOutput = True
psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden
psi.UseShellExecute = False
Dim myProcess As Process = Process.Start(psi)
Dim output As String = myProcess.StandardOutput.ReadToEnd()
myProcess.WaitForExit(180000)
If (myProcess.HasExited) Then
Throw New Exception("FTP failed due to time-out. Please check the connectivity to FTP server.")
End If
FTPFile = "Success"
End If如果批处理文件的执行没有在3分钟内完成,我希望"myProcess“应该退出。但是,即使批处理文件在不到2秒的时间内完成执行,myProcess.HasExited
返回True。如果我输入2000而不是180000,则该过程运行良好。这里出了什么问题?
发布于 2013-06-21 21:50:05
myProcess.HasExited只会告诉您进程是否退出。如果您对进程是否因超时而退出感兴趣,您应该使用
If Not myProcess.WaitForExit(180000) Then
Throw New Exception("FTP failed due to time-out. Please check the connectivity to FTP server.")
End If https://stackoverflow.com/questions/17235924
复制相似问题