找不到命名空间名称"DispatcherTimer"

nat*_*ate 2 c# namespaces reference .net-assembly dispatchertimer

我正在尝试使用调度计时器,但我的c#app无法找到命名空间.这是错误:

找不到类型或命名空间名称'DispatcherTimer'(您是否缺少using指令或程序集引用?)

这是我正在使用的:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
Run Code Online (Sandbox Code Playgroud)

这是代码:

DispatcherTimer timer1 = new DispatcherTimer();
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 8

DispatcherTimer不是命名空间 - 它是System.Windows.Threading命名空间和WindowsBase程序集中的一个类.所以你需要

using System.Windows.Threading;
Run Code Online (Sandbox Code Playgroud)

通常,搜索缺少的类型名称和"MSDN"足以找出在何处查找类型.

  • @nate:然后听起来好像你没有编写WPF或Silverlight应用程序 - 听起来你正在编写一个Windows Forms应用程序,并且`DispatcherTimer`并不适用于此.请查看`System.Windows.Forms.Timer`. (2认同)