// Start private void button1_Click(object sender, EventArgs e) { if (this.timer != null) // The "Reset" button is pressed. { Console.WriteLine("The timer already exists.\n Now we are restarting it."); if (this.old == true) // If it's a new timer, it's not running yet. // In this case, we should reset and restart. { this.old = false; this.timer.reset(); Thread t1 = new Thread(new ThreadStart(timer.onStart)); t1.Start(); } else // Otherwise, we shall just reset it. { this.timer.reset(); } this.button2.Text = "Pause"; // Once it's reset, the resume/pause button should also be reset. } else // The "Start" button is pressed { // Create a timer and start running it. Console.WriteLine("Now we are starting a new timer."); this.button1.Text = "Reset"; this.button2.Text = "Pause"; if (this.ChooseStyle == ChooseStyle.TimeSpan) { this.timer = TimerBuildSwitcher(this.duration, this.option, this.count_limit); } this.register_receivers(); // Register all the receiver functions. this.direction = TimerDirection.Right; Thread t1 = new Thread(new ThreadStart(timer.onStart)); t1.Start(); } }
// Pause/Resume private void button2_Click(object sender, EventArgs e) { // Switch the text on the button. if (button2.Text == "Pause") { button2.Text = "Resume"; } else { button2.Text = "Pause"; } if (this.old == true) // A loaded timer, not start yet, now start it. { this.old = false; this.direction = TimerDirection.Right; Thread t1 = new Thread(new ThreadStart(timer.onStart)); this.timer.onPauseResume(); t1.Start(); } else { if (this.timer == null) { Console.WriteLine("Warning! The timer is not runing."); MessageBox.Show("Warning! The timer is not runing.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // A running new timer. { this.timer.onPauseResume(); } } }
/// <summary> /// Used to increase/decrease time picker value /// </summary> /// <param name="period"></param> /// <param name="timerDirection"></param> private void RunButtonPressTimer(int period, TimerDirection timerDirection) { _runTimer = true; _buttonPressTimerDuration = 0; Device.StartTimer(TimeSpan.FromMilliseconds(period), () => { if (_buttonPressTimerDuration > 3000 && timerDirection == TimerDirection.Decrement) { UpdateLabelText(DateTime.MinValue.AddMinutes(Step)); return(false); } else if (_buttonPressTimerDuration > 3000 && timerDirection == TimerDirection.Increment) { UpdateLabelText(DateTime.MinValue.AddHours(MaxHours)); return(false); } else if (timerDirection == TimerDirection.Decrement) { DecrementTime(Step); } else if (timerDirection == TimerDirection.Increment) { IncrementTime(Step); } _buttonPressTimerDuration += _buttonPressTimerPeriod; return(_runTimer); }); }
public Timer(TimerDirection direction = TimerDirection.Forward, float startDuration = 0) { Stop(); _duration = startDuration; _multiplier = 1; _destroyBuffer = new List <int>(); actions = new List <TimeoutAction>(); }
public TimeoutAction(TimerDirection direction_, double timeout_, TimeoutBehaviour timeoutBehaviour_, Action action_) { triggered = false; direction = direction_; timeout = timeout_; timeoutBehaviour = timeoutBehaviour_; action = action_; }
/// <summary> /// Starts the specified start time. /// </summary> /// <param name="startTime">The start time.</param> /// <param name="endTime">The end time.</param> /// <param name="direction">The direction.</param> /// <param name="callerSyncObject">The caller synchronize object.</param> public void Start(TimeSpan startTime, TimeSpan endTime, TimerDirection direction, System.ComponentModel.ISynchronizeInvoke callerSyncObject = null) { this.direction = direction; this.internalTimer.SynchronizingObject = callerSyncObject; this.internalTimer.Interval = this.timerIntervalInMilliseconds; currentTime = new TimeSpan(startTime.Ticks); this.internalTimer.Start(); }
/// <summary> /// Starts the Timing Clock. /// </summary> /// <param name="direction">The direction.</param> /// <param name="startTime">The start time.</param> /// <returns></returns> public void Start(TimerDirection direction, TimeSpan startTime) { if (internalClock.Enabled) { internalClock.Stop(); } this.currentTime = this.startTime = startTime; this.direction = direction; // Reset the clock ReSetCurrentTime(); this.internalClock.Start(); }
// When chosing the direction. private void rightToolStripMenuItem_Click(object sender, EventArgs e) { this.direction = TimerDirection.Right; }
public void setDirection(TimerDirection direction) { _direction = direction; }
//Setters public int addAction(TimerDirection direction, double timeout, TimeoutBehaviour timeoutBehaviour, Action action) { actions.Add(new TimeoutAction(direction, timeout, timeoutBehaviour, action)); return(actions.Count - 1); }
public void Reverse() { _direction = (_direction == TimerDirection.Forward ? TimerDirection.Backward : TimerDirection.Forward); }