Question

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();
Was it helpful?

Solution

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.

OTHER TIPS

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

You must Add WindowsBase in your references so you can use the System.Windows.Threading.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top