问题
Why do I get The type or namespace name 'ManagementEventWatcher' not found in the following code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Management;
class Program {
public ManagementEventWatcher mgmtWtch;
static void Main(string[] args)
{
InitializeComponent();
mgmtWtch = new System.Management
.ManagementEventWatcher("Select * From Win32_ProcessStartTrace");
mgmtWtch.EventArrived += new
System.Management.EventArrivedEventHandler(mgmtWtch_EventArrived);
mgmtWtch.Start();
}
}
I think my dll doesn't have this method, but how to check?
回答1:
Have you added the reference as well as the using? eg
using System.Management;
is not enough.. you need to add the reference to System.Management too.
回答2:
Your Main method is static, but your mgmWtch variable is not. Declare it as as static.
来源:https://stackoverflow.com/questions/6218272/the-type-or-namespace-name-managementeventwatcher-not-found