简体   繁体   中英

namespace name 'DispatcherTimer' could not be found

I am trying to use a dispatch timer, but my c# app can't find the namespace. This is the error:

The type or namespace name 'DispatcherTimer' could not be found (are you missing a using directive or an assembly reference?)

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. 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.

The Dispatcher class is in WindowsBase.dll. You MUST add that reference to your project to use "using System.Windows.Threading;" <>

Add this using:

using System.Windows.Threading;

MSDN

Isn't in the System.Windows.Threading namespace and not the System.Threading namespace?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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