// Run when got the after alarm event. private void AfterAlarmReceiver(object sender, EventArgs e) { Console.WriteLine("Just after alarm."); Action DoAction = delegate() { if (this.alarmOffStyle == AlarmOffStyle.Auto) // If the alarm form is set to be close automatically. { if (this.alarmRise != null) { this.alarmRise.Close(); } else { Console.WriteLine("?"); } } textBox1.Clear(); }; if (this.InvokeRequired)// Cross-thread operation { ControlExtensions.UIThreadInvoke(this, delegate { DoAction(); }); } else { DoAction(); } }
private void AlarmReceiver(object sender, EventArgs e)//When time is up, create an alarm window { Console.WriteLine("Just on alarm."); Action DoAction = delegate() { textBox1.Clear(); textBox1.AppendText("Alarming!"); this.TopMost = true; //Window jump to the top when alarming. this.Show(); this.alarmRise = new AlarmRiseForm(this.SoundPointer); //hope to save the SoundPointer in .json when chosen in the ContextMenuStrip1 in the future this.alarmRise.Show(); }; if (this.InvokeRequired) // Cross-thread operation { ControlExtensions.UIThreadInvoke(this, delegate { DoAction(); }); } else { DoAction(); } }
private void UpdateReceiver(object sender, Timer.UpdateEventArgs e) { Console.WriteLine("Just Update the timer."); Action DoAction = delegate() { this.displayer.Clear(); switch (this.timer.timerOption) { case TimerOption.Timing: // If it's a timing timer, just show the time. this.displayer.AppendText(e.Diff.ToString("hh':'mm':'ss'.'fff")); break; default: // Else, show the time left and the progress. if (e.Expire) { this.refreshProgressBar(0); // When it's expired, the progress bar should be run to the end. } else { double percent = (e.Diff.TotalMilliseconds / e.Orig.TotalMilliseconds); this.refreshProgressBar(percent); // Show progress bar according to the percentage. } this.displayer.AppendText(e.Diff.ToString("hh':'mm':'ss'.'fff")); break; } }; if (this.InvokeRequired)// Cross-thread operation { ControlExtensions.UIThreadInvoke(this, delegate { DoAction(); }); } else { DoAction(); } }
// Receive the event when start a timer in the TimerChooseForm UI logic. private void ChosenReceiver(object sender, TimerChooseForm.ChosenEventArgs e) { Console.WriteLine("Just Selected and started the timer."); Action DoAction = delegate() { TimerForm f = new TimerForm(e.duration, e.option, e.cycle_limit); f.Show(); this.TCF.Close(); }; if (this.InvokeRequired) { ControlExtensions.UIThreadInvoke(this, delegate { DoAction(); }); } else { DoAction(); } }
// Run when the choose unit is closed. private void ClosedEventReceiver(object sender, FormClosedEventArgs e) { Action DoAction = delegate() { if (this.TCF != null) { this.TCF = null; } }; if (this.InvokeRequired) { ControlExtensions.UIThreadInvoke(this, delegate { DoAction(); }); } else { DoAction(); } }
// Run when got the end event. private void EndReceiver(object sender, EventArgs e) { Console.WriteLine("Just end the timer."); Action DoAction = delegate() { this.textBox1.Clear(); this.textBox1.AppendText("Now the Timer is ended!"); }; if (this.InvokeRequired)// Cross-thread operation { ControlExtensions.UIThreadInvoke(this, delegate { DoAction(); }); } else { DoAction(); } }