EventArrized在ManagementEventWatcher vb.Net中不工作

EventArrized在ManagementEventWatcher vb.Net中不工作,.net,vb.net,visual-studio-2012,.net,Vb.net,Visual Studio 2012,函数Watcher\u EventArrived不工作。 我也添加了参考,但它仍然不起作用 用声明变量watcher,否则不能使用-子句 另见: Dim watcher As ManagementEventWatcher Public Sub Main() Dim monitoredProcess = "Notepad.exe" Dim query As WqlEventQuery = New WqlEventQuery("__InstanceCreationEvent",

函数
Watcher\u EventArrived
不工作。
我也添加了参考,但它仍然不起作用


用声明变量
watcher
,否则不能使用-子句

另见:

Dim watcher As ManagementEventWatcher

Public Sub Main()
    Dim monitoredProcess = "Notepad.exe"

    Dim query As WqlEventQuery = New WqlEventQuery("__InstanceCreationEvent", New TimeSpan(0, 0, 1), "TargetInstance isa ""Win32_Process"" And TargetInstance.Name = """ & monitoredProcess & """")

    watcher = New ManagementEventWatcher()
    watcher.Query = query

    'This starts watching asynchronously, triggering EventArrived events every time a new event comes in.
    'You can do synchronous watching via the WaitForNextEvent() method
    watcher.Start()

End Sub

Public Sub Watcher_EventArrived(sender As Object, e As EventArrivedEventArgs) Handles watcher.EventArrived
    Console.WriteLine("Working")
End Sub
Dim WithEvents watcher As ManagementEventWatcher