//SoundPlayer player = new SoundPlayer(); private void Timer_Tick(object sender, EventArgs e) { if (this.ProcessWave.Value > 0) { this.ProcessWave.Value--; this.LeftTimeLabel.Text = this.LeftTimeString(this.ProcessWave.Value); if (isWorking) { this.WorkingState.Text = "精神小伙工作中…"; } else { this.WorkingState.Text = "精神小伙休息中…"; } } else if (this.ProcessWave.Value == 0) { if (isWorking) { new Thread(() => { TTSUtils.SayChinese("休息时间到"); }).Start(); player.Stop(); player.Open(CurrentFile = new Uri(Application.StartupPath + "\\alarms\\Helium.wav")); player.Play(); //启用新线程播放 this.WorkingState.Text = "精神小伙休息中…"; isWorking = false; isWaiting = true; this.ProcessWave.MaxValue = RelaxTime * 60; this.ProcessWave.Value = this.ProcessWave.MaxValue; } else { new Thread(() => { TTSUtils.SayChinese("工作时间到"); }).Start(); player.Stop(); player.Open(CurrentFile = new Uri(Application.StartupPath + "\\ringtones\\Callisto.wav")); player.Play(); //启用新线程播放 )); this.WorkingState.Text = "精神小伙要工作了…"; isWorking = true; isWaiting = false; this.ProcessWave.MaxValue = WorkingTime * 60; this.ProcessWave.Value = this.ProcessWave.MaxValue; } this.Cirlcle = false; } }
private void SystemTimer_Tick(object sender, EventArgs e) { DateTime now = DateTime.Now; if (this.ucCheckBox_CloseTime.Checked && ((int)(now.TimeOfDay.TotalSeconds)).Equals((int)this.CloseTime.TimeOfDay.TotalSeconds)) { MessageBox.Show("系统将于60s后自动关机,请及时关闭保存文件!", "番茄钟", MessageBoxButtons.OK, MessageBoxIcon.Information); CancelShutDown = new CancellationTokenSource(); new Thread(() => { int count = 0; this.Invoke(new Action(() => { this.timer.Enabled = true; this.btn_Play_Click(null, null); this.player.Stop(); })); while (count < 60) { count++; if (CancelShutDown.IsCancellationRequested == true) { return; } this.WorkingState.Text = String.Format("{0}S后关闭系统", 60 - count); Thread.Sleep(1000); } if (MessageBox.Show("系统即将关机,请确认文件是否全部保存确定立即关机,取消进入休眠模式!", "番茄钟", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { WindowsController.ExitWindows(RestartOptions.PowerOff, false); } else { WindowsController.ExitWindows(RestartOptions.Hibernate, false); } }).Start(); } string flag = ""; if (now.Hour > 0 && now.Hour <= 5) { flag = "凌晨"; } else if (now.Hour > 5 && now.Hour <= 7) { flag = "早晨"; } else if (now.Hour > 7 && now.Hour <= 11) { flag = "上午"; } else if (now.Hour > 11 && now.Hour <= 13) { flag = "中午"; } else if (now.Hour > 13 && now.Hour <= 17) { flag = "下午"; } else if (now.Hour > 17 && now.Hour <= 19) { flag = "傍晚"; } else if (now.Hour > 19 && now.Hour <= 23) { flag = "晚上"; } else if (now.Hour > 23 && now.Hour <= 0) { flag = "子夜"; } this.label1.Text = now.Year.ToString() + "/" + now.Month.ToString() + "/" + now.Day.ToString() + " " + flag + now.Hour.ToString("D2") + ":" + now.Minute.ToString("D2") + ":" + now.Second.ToString("D2"); if ((now.Minute == 0 || now.Minute == 30) && now.Second == 20) { new Thread(() => { string minutes = ""; if (now.Minute == 30) { minutes = "半"; } TTSUtils.SayChinese("现在是:" + flag + (now.Hour % 12).ToString() + "点" + minutes); }).Start(); } }