首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ProcessStartInfo .WaitForExit()工作不正常

ProcessStartInfo .WaitForExit()工作不正常
EN

Stack Overflow用户
提问于 2013-06-21 21:02:59
回答 1查看 1.1K关注 0票数 0

因此,我有这段代码来调用批处理文件。

代码语言:javascript
复制
        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,则该过程运行良好。这里出了什么问题?

EN

回答 1

Stack Overflow用户

发布于 2013-06-21 21:50:05

myProcess.HasExited只会告诉您进程是否退出。如果您对进程是否因超时而退出感兴趣,您应该使用

代码语言:javascript
复制
If Not myProcess.WaitForExit(180000) Then
    Throw New Exception("FTP failed due to time-out. Please check the connectivity to FTP server.")
End If   
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17235924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档