First off, you're using the UI dispatcher to schedule your timer tick. To prove this, add the following to your constructor.
if(DPS.Dispatcher != Dispatcher.CurrentDispatcher || // UI thread, UI dispatcher
DPS.Dispatcher != Application.Current.Dispatcher || // Also the UI dispatcher
DPS.Dispatcher != Dispatcher) // the window's dispatcher
throw new InvalidOperationException("Will is wrong");
You'll note I'm right. So, the UI thread is busy with mouse events when you wiggle your mouse around, which as Hans said have much higher priority than your timer tick. Feh on it.
You can get around this by using a different timer implementation that runs on a background thread, then trapse over to the UI thread to update the UI on tick.
I'm a fan of MVVM, and bindings automatically handle invoking updates on the UI thread for you, so my repro is slightly different than yours.
First, add a binding to the label in the UI.
<Label Content="{Binding Count}" />
We'll reuse the Click event on the button, creating an ICommand for that is a little overboard. Next, update your Window's code to look like this
public partial class MainWindow : Window
{
VM vm = new VM();
public MainWindow()
{
InitializeComponent();
DataContext = vm;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
vm.Start();
}
class VM : INotifyPropertyChanged
{
double dps1 = 2;
double count;
Timer timer;
PropertyChangedEventArgs args = new PropertyChangedEventArgs(nameof(Count));
public VM()
{
timer = new Timer();
timer.Interval = .0001;
timer.Elapsed += (o, e) => Count = (count += dps1 / 2500);
}
public double Count
{
get
{
return count;
}
set
{
count = value;
PropertyChanged?.Invoke(this, args);
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void Start()
{
timer.Start();
}
}
}
I'm using System.Windows.Threading.Timer to handle my ticks, which has an Interval in ms (.0001ms is a tick, roughly sorta). If you run this example, your UI won't lag anymore.