private void button1_Click(object sender, RoutedEventArgs e) { this.button1.IsEnabled = false; this.button1.Content = "已运行"; workService = new WorkService(); workService.LoadDriver(obColl); DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(timer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); dispatcherTimer.Start(); //web启动 workService.StartServer(); }
public MainWindow() { InitializeComponent(); //显示成托盘 this.Visibility = Visibility.Hidden; this.notifyIcon = new NotifyIcon(); this.notifyIcon.BalloonTipText = "托盘应用程序正在运行!"; this.notifyIcon.Text = "托盘应用程序!"; this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath); this.notifyIcon.Visible = true; this.notifyIcon.ShowBalloonTip(1000); this.notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick); System.Windows.Forms.MenuItem item1 = new System.Windows.Forms.MenuItem("显示主界面"); item1.Click += new EventHandler(item1_Click); System.Windows.Forms.MenuItem item2 = new System.Windows.Forms.MenuItem("退出"); item2.Click += new EventHandler(item2_Click); System.Windows.Forms.MenuItem[] menuItems = new System.Windows.Forms.MenuItem[] { item1, item2 }; this.notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(menuItems); this.StateChanged += new EventHandler(MainWindow_StateChanged); this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); //启动服务 service.StartServer(); }