protected override void OnActivated(EventArgs e) { base.OnActivated(e); DateTime startup = getStartupTime(); Label time = MainWindow.FindName("time") as Label; time.Content = startup.ToString(); Label span = MainWindow.FindName("span") as Label; new Thread(_ => { while (true) { Dispatcher.Invoke(() => { var spanTime = DateTime.Now - startup; span.Content = String.Format("{0}小时{1}分钟", spanTime.Hours, spanTime.Minutes); if (spanTime.Hours >= 9) { span.Foreground = Brushes.Red; span.FontWeight = FontWeights.Bold; //notifyIcon.ShowBalloonTip(2000, "", "可以下班了", System.Windows.Forms.ToolTipIcon.None); } }); Thread.Sleep(1000); } }).Start(); }