简体   繁体   English

找不到命名空间名称“DispatcherTimer”

[英]namespace name 'DispatcherTimer' could not be found

I am trying to use a dispatch timer, but my c# app can't find the namespace. 我正在尝试使用调度计时器,但我的c#app无法找到命名空间。 This is the error: 这是错误:

The type or namespace name 'DispatcherTimer' could not be found (are you missing a using directive or an assembly reference?) 找不到类型或命名空间名称'DispatcherTimer'(您是否缺少using指令或程序集引用?)

Here is what I am 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;

Here is the code: 这是代码:

DispatcherTimer timer1 = new DispatcherTimer();

DispatcherTimer is not a namespace - it's a class within the System.Windows.Threading namespace and the WindowsBase assembly. DispatcherTimer不是命名空间 - 它是System.Windows.Threading命名空间和WindowsBase程序WindowsBase的一个类。 So you need 所以你需要

using System.Windows.Threading;

In general, a search for the missing type name and "MSDN" is enough to find out where to find a type. 通常,搜索缺少的类型名称和“MSDN”足以找出在何处查找类型。

The Dispatcher class is in WindowsBase.dll. Dispatcher类位于WindowsBase.dll中。 You MUST add that reference to your project to use "using System.Windows.Threading;" 您必须将该引用添加到您的项目以使用“using System.Windows.Threading;” <> <>

Add this using: 添加此使用:

using System.Windows.Threading;

MSDN MSDN

Isn't in the System.Windows.Threading namespace and not the System.Threading namespace? 是不在System.Windows.Threading命名空间而不是System.Threading命名空间?

http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx

您必须在引用中添加WindowsBase,以便可以使用System.Windows.Threading。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM