private void Form1_Load(object sender, EventArgs e) { ProcessCache.ProcessComparerComparisonType = ComparisonType.PID; ProcessCache.ParentListView = listViewProcesses; // Init before subscription ProcessCache.InitWQL(); // Subscribe ProcessCache.watchStartEvent.EventArrived += WatchStartEvent_EventArrived; ProcessCache.watchStopEvent.EventArrived += WatchStopEvent_EventArrived; #region Process cache event subscription ProcessCache.OnProcessKilled += ProcessCache_OnProcessKilled; ProcessCache.OnProcessStarted += ProcessCache_OnProcessStarted; #endregion // Initialize menu items MenuItem[] menuItems = new MenuItem[] { new MenuItem("Kill", OnProcessKilled) // Add get thread information }; _contextMenu = new ContextMenu(menuItems); // Fill Hashset with current processes. ProcessCache.AddRangeHashSet(Process.GetProcesses()); // Init. list view, with hashset processes then convert all items to list view array listViewProcesses.Items.AddRange(ProcessCache.Instance.ConvertToListViewArray()); }
// start event private void WatchStartEvent_EventArrived(object sender, EventArrivedEventArgs e) { int processId = int.Parse(e.NewEvent.Properties["ProcessID"].Value.ToString()); try { var tempProcObj = new ProcessObject(); var proc = Process.GetProcessById(processId); ProcessCache.AddHashSet(proc); } catch (Exception f) { Debug.WriteLine(f.Message); } }
// stop event private void WatchStopEvent_EventArrived(object sender, EventArrivedEventArgs e) { int processId = int.Parse(e.NewEvent.Properties["ProcessID"].Value.ToString()); ProcessCache.RemoveHashSet(processId); }