Search code examples
c#referencenamespaces.net-assemblydispatchertimer

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

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.