private void WatcherEventArrived(object sender, EventArrivedEventArgs e)
        {
            string eventType = e.NewEvent.ClassPath.ClassName;
            System.Console.WriteLine("Process "+eventType);
            var proc = new Win32_Process(e.NewEvent["TargetInstance"] as ManagementBaseObject);

            ProcessCreated.SafeInvoke(this, proc);
        }
Beispiel #2
0
 static void procWatcher_ProcessCreated(WMI.Win32.Win32_Process process)
 {
     Console.Write("Created " + process.Name + " " + process.ProcessId + "  " + "DateTime:" + DateTime.Now + "\n");
 }
 private void ProcessCreated(Win32_Process proc)
 {
     var processId = proc.ProcessId;
     ReIndexProcess((int)processId);
 }
        private void watcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            string eventType = e.NewEvent.ClassPath.ClassName;
            Win32_Process proc = new
                Win32_Process(e.NewEvent["TargetInstance"] as ManagementBaseObject);

            switch (eventType)
            {
                case "__InstanceCreationEvent":
                    ProcessCreated(proc);
                    break;
                case "__InstanceDeletionEvent":
                    ProcessDeleted(proc);
                    break;
                case "__InstanceModificationEvent":
                    ProcessModified(proc);
                    break;
            }
        }
 private void ProcessModified(Win32_Process proc)
 {
     ProcessCreated(proc);
 }
 private void ProcessDeleted(Win32_Process proc)
 {
     Log.Debug("Process {0} ({1}) deleted", proc.Name, proc.ProcessId);
     Process process;
     var storage = _sourceStorageFactory.SourceStorageFor(_source.Id);
     if (_cachedProcesses.TryRemove(proc.ProcessId, out process))
     {
         storage.RemoveItems(_source, process);
     }
     else
     {
         storage.RemoveItems(_source, proc);
     }
 }