using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Timers;
namespace WpfApplication1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
///
public partial class MainWindow : Window
{
Timer t1 = new Timer();
public MainWindow()
{
InitializeComponent();
t1.Interval = 1000;
t1.Enabled = true;
}
private void t1_Tick(object sender, System.EventArgs e)
{
t1.Enabled = false;
MessageBox.Show("需要休息了,开机已经2小时了");
t1.Enabled = true; //如果不先把timer1设成false,对话框会一直弹下去。
}
}
} |