如何用一个程序监视另一个程序是否退出
发布网友
发布时间:2022-04-22 02:15
我来回答
共2个回答
热心网友
时间:2024-04-11 00:10
Dim p As New Process
p.StartInfo="d:\test.docx"
p.Start
p.WaitForExit() '等待程序结束
Msgbox("文档已经关闭")
如果是单线程程序,在文档关闭前就会一直卡住,所以要用多线程处理。
热心网友
时间:2024-04-11 00:10
用FileSystemWatcher类。
Imports System.IO
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim FsWatcher As New FileSystemWatcher
With FsWatcher
.Filter = "~$test.docx"
.Path = "D:\"
.NotifyFilter = IO.NotifyFilters.Size
AddHandler FsWatcher.Deleted, AddressOf IsFileDeleted
.BeginInit()
End With
Catch ex As Exception
End Try
End Sub
Sub IsFileDeleted(ByVal sender As Object, ByVal e As FileSystemEventArgs)
If e.ChangeType = WatcherChangeTypes.Deleted Then
MsgBox("文件已经关闭")
End If
End Sub