public ClipboardClear() { InitializeComponent(); // Set the state of the save button validateSaveButton(); // Hide the window in the system tray to start this.ShowInTaskbar = false; notifyIcon.Visible = true; hideWindow(); // Prepare the main timer clearClipboardTimer = new System.Timers.Timer(); clearClipboardTimer.Interval = Properties.Settings.Default.TimeToClearClipboard * 1000; clearClipboardTimer.AutoReset = false; clearClipboardTimer.Elapsed += new System.Timers.ElapsedEventHandler(clearClipboardTimerElapsed); // Prepare the retry timer retryClearClipboardTimer = new System.Timers.Timer(); retryClearClipboardTimer.AutoReset = false; retryClearClipboardTimer.Interval = 5000; retryClearClipboardTimer.Elapsed += new System.Timers.ElapsedEventHandler(clearClipboardTimerElapsed); // Setup the delegate timerElapsedDelegate = new TimerElapsedDelegate(clearClipboard); // Add in the clipboard listener AddClipboardFormatListener(this.Handle); }
static void Main() { int ticksCount = 10; int interval = 2000; // milliseconds TimerElapsedDelegate timerElapsedDelegate = new TimerElapsedDelegate(PrintTicksLeft); Timer timer = new Timer(ticksCount, interval, timerElapsedDelegate); Console.WriteLine("Timer started for {0} ticks, a tick occurring once every {1} second(s).", ticksCount, interval / 1000); Thread timerThread = new Thread(new ThreadStart(timer.Run)); timerThread.Start(); }
private void _Timer_Elapsed(object sender, ElapsedEventArgs e) { try { if (!Dispatcher.CheckAccess()) { TimerElapsedDelegate d = _Timer_Elapsed; Dispatcher.Invoke(d, sender, e); } else { _Timer.Stop(); if (!hidePanel()) { _Timer.Start(); } } } catch (Exception ex) { PNStatic.LogException(ex); } }
private void _DelayTimer_Elapsed(object sender, ElapsedEventArgs e) { try { if (!Dispatcher.CheckAccess()) { TimerElapsedDelegate d = _DelayTimer_Elapsed; Dispatcher.Invoke(d, sender, e); } else { _DelayTimer.Stop(); var pt = PointToScreen(Mouse.GetPosition(this)); if (new Rect(Left, Top, ActualWidth, ActualHeight).Contains(pt)) { mouseEntered(); } } } catch (Exception ex) { PNStatic.LogException(ex); } }
public Timer(int ticksCount, int interval, TimerElapsedDelegate callback) { this.ticksCount = ticksCount; this.interval = interval; this.callback = callback; }