private void ProcessWatchTimer_Tick(object sender, EventArgs e) { while (qadd.Count > 0) { PolProcess pol = new PolProcess(qadd.Dequeue()); ToolStripMenuItem menuItem = new ToolStripMenuItem(pol.Title); menuItem.Tag = pol; WindowerMenuItemProcess.DropDownItems.Add(menuItem); } while (qdel.Count > 0) { Process p = qdel.Dequeue(); foreach (ToolStripMenuItem menuItem in WindowerMenuItemProcess.DropDownItems) { PolProcess pol = (PolProcess) menuItem.Tag; if (pol != null && pol.Pid == p.Id) { WindowerMenuItemProcess.DropDownItems.Remove(menuItem); break; } } } if (WindowerMenuItemProcess.DropDownItems.Count == 1) { ToolStripMenuItem menuItem = (ToolStripMenuItem) WindowerMenuItemProcess.DropDownItems[0]; if (_windower == null || !menuItem.Checked) WindowerMenuItemProcess_DropDownItemClicked(this, new ToolStripItemClickedEventArgs(menuItem)); } if (_windower != null && WindowerMenuItemProcess.DropDownItems.Count == 0) { _windower = null; WindowerInstanceChanged.Invoke(this, new EventArgs()); } ProcessWatchTimerTick.Invoke(this, new EventArgs()); }
private void InitProcessHandler() { _windower = null; qadd = new Queue<Process>(); qdel = new Queue<Process>(); ppw = new PolProcessWatcher(); ppw.ProcessAdded += new EventHandler<PolProcessWatcherEventArgs>(ProcessAddedEventHandler); ppw.ProcessRemoved += new EventHandler<PolProcessWatcherEventArgs>(ProcessRemovedEventHandler); ppw.Start(); }
private void WindowerMenuItemProcess_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { foreach (ToolStripMenuItem item in WindowerMenuItemProcess.DropDownItems) item.Checked = false; ToolStripMenuItem menuItem = (ToolStripMenuItem) e.ClickedItem; menuItem.Checked = true; PolProcess pol = (PolProcess) menuItem.Tag; if (pol == null || (_windower != null && _windower.Pid == pol.Pid)) return; _windower = new XIWindower(pol.Pid); WindowerInstanceChanged.Invoke(this, new EventArgs()); }