
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.25 KB | hits: 12 | expires: Never
How can I use threading to 'tick' a timer to be accessed by other threads?
private DateTime _lastTap;
public void TapHandler()
{
DateTime now = DateTime.UtcNow;
TimeSpan span = now - lastTap;
_lastTap = now;
if (span < TimeSpan.FromSeconds(1)) {...}
}
private Stopwatch _stopwatch = new Stopwatch();
public void TapHandler()
{
TimeSpan elapsed = _stopwatch.Elapsed;
_stopwatch.Restart();
if (elapsed < TimeSpan.FromSeconds(1)) {...}
}
private static DispatcherTimer clickTimer =
new DispatcherTimer(
TimeSpan.FromMilliseconds(SystemInformation.DoubleClickTime),
DispatcherPriority.Background,
mouseWaitTimer_Tick,
Dispatcher.CurrentDispatcher);
private void Button_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
// Stop the timer from ticking.
myClickWaitTimer.Stop();
Trace.WriteLine("Double Click");
e.Handled = true;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
myClickWaitTimer.Start();
}
private static void mouseWaitTimer_Tick(object sender, EventArgs e)
{
myClickWaitTimer.Stop();
// Handle Single Click Actions
Trace.WriteLine("Single Click");
}