【问题标题】:The type or namespace name 'ManagementEventWatcher' not found找不到类型或命名空间名称“ManagementEventWatcher”
【发布时间】:2011-06-02 17:53:18
【问题描述】:

为什么我在以下代码中找不到类型或命名空间名称'ManagementEventWatcher'

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();
    }
}

我觉得我的dll没有这个方法,但是怎么检查呢?

【问题讨论】:

标签: c# managementeventwatcher


【解决方案1】:

您是否添加了引用以及使用?例如

using System.Management;

还不够……你还需要添加对 System.Management 的引用。

【讨论】:

  • 好的,你有例子吗?我刚刚开始学习 c# 我找到了 \o/ 谢谢 BugFinder
【解决方案2】:

您的 Main 方法是静态的,但您的 mgmWtch 变量不是。将其声明为静态。

【讨论】:

  • 没错,但问题总是她:/
  • 您使用的是哪个版本的 Visual Studio / .net?
  • BugFinder 发现了一个“bug”...我只是忘记在项目中添加引用。不过谢谢你的帮助
猜你喜欢
  • 1970-01-01
  • 2017-07-12
  • 2011-05-13
  • 2013-03-25
  • 2012-06-19
  • 2017-11-29
  • 2012-09-27
  • 2011-05-06
相关资源
最近更新 更多