欢迎光临
我们一直在努力

使用vb.net等待外部程序运行完毕才继续-.NET教程,Windows开发

建站超值云服务器,限时71元/月

上次我已介绍如何运行外部程序,今天我继续讲这一话题:
1.有好多时,我们需要调用外部的exe程序,并且要等它运行完毕,我们才可以继续下面的动作,那我们怎样去实现了,请看以下代码.
        怎样等待外部程序运行完毕.
        从系统资料夹读入文件
        dim sysfolder as string = _
                    environment.getfolderpath(environment.specialfolder.system)
        创建一个新的进程结构
        dim pinfo as new processstartinfo()
        设置其成员filename为系统资料的eula.txt
        pinfo.filename = sysfolder & "\eula.txt"
        运行该文件
        dim p as process = process.start(pinfo)
        等待程序装载完成
        p.waitforinputidle()
        等待进行程退出
        p.waitforexit()
        继续执行下面的代码
        messagebox.show("继续执行代码")

2.我们想在5秒钟后,强行关闭它.而不是需要我手工关闭.
    设置退出时间
    dim timeout as integer = 5000
    dim sysfolder as string = _
         environment.getfolderpath(environment.specialfolder.system)
    dim pinfo as new processstartinfo()
    pinfo.filename = sysfolder & "\eula.txt"
    dim p as process = process.start(pinfo)
    p.waitforinputidle()
    p.waitforexit(timeout)
    检查是否在超时前已关闭了.
    if p.hasexited = false then
        进行程还在运行
        看进程有没有回应
        if p.responding then
            p.closemainwindow() 关闭窗口
        else
            p.kill()  强行中断
        end if
    end if
    messagebox.show("继续执行代码")

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用vb.net等待外部程序运行完毕才继续-.NET教程,Windows开发
分享到: 更多 (0)

相关推荐

  • 暂无文章