示例#1
0
        /// <summary>Gets a sequence containing a Process object for each process with
        /// the one of the given names in the monitored session. </summary>
        /// <param name="names">The names.</param>
        /// <exception cref="ArgumentNullException">names cannot be null.</exception>
        public IEnumerable <Process> GetSessionProcessesWithName(IEnumerable <string> names)
        {
            if (names == null)
            {
                throw new ArgumentNullException(nameof(names));
            }

            return(SessionProcesses.Where(p => names.Contains(p.ProcessName.ToUpper())));
        }
示例#2
0
        /// <summary>Checks for process changes, then sleeps the thread. </summary>
        private void CheckForProcessChanges()
        {
            while (true)
            {
                //Check current processes
                var currentProcesses = new RunningProcessCollection(
                    SessionProcesses
                    .GroupBy(p => p.ProcessName)
                    .Select(g => new RunningProcess(g.Key, g.Count()))
                    .OrderBy(rp => rp.Name)); //sorting allows sequence comparison

                //If different than last check, publish update
                if (!currentProcesses.SequenceEqual(this.Processes))
                {
                    this.Processes = currentProcesses;
                    OnPropertyChanged(nameof(this.Processes));
                }

                //Wait to refresh
                Thread.Sleep(refreshMilliseconds);
            }
        }