等待进程完成 [英] Waiting For Process To Complete

查看:62
本文介绍了等待进程完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在继续下一行代码之前,有没有办法暂停进程或等待进程完成?

Is there any way to pause a process or wait unitl the process is complete before continuing onto the next line of code?

这是我当前压缩所有 PDF 然后删除的过程.目前,它在压缩完成之前删除文件.有没有办法暂停/等待进程完成?

Here is my current process to zip all PDFs and then delete. Currently, its deleting files before the zipping is complete. Is there a way to pause/wait until the process is complete?

    Dim psInfo As New System.Diagnostics.ProcessStartInfo("C:\Program Files\7-Zip\7z.exe ", Arg1 + ZipFileName + PathToPDFs)
    psInfo.WindowStyle = ProcessWindowStyle.Hidden
    System.Diagnostics.Process.Start(psInfo)

    'delete remaining pdfs
    For Each foundFile As String In My.Computer.FileSystem.GetFiles("C:\Temp\", FileIO.SearchOption.SearchAllSubDirectories, "*.pdf")
        File.Delete(foundFile)
    Next

推荐答案

可以使用process.WaitForExit方法

WaitForExit 可以让当前线程等待相关进程退出.

WaitForExit can make the current thread wait until the associated process to exit.

链接:http://msdn.microsoft.com/fr-fr/library/system.diagnostics.process.waitforexit(v=vs.80).aspx

这篇关于等待进程完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆