Пример #1
0
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            // temp storing the running processes
            List <Process> rProcs = new List <Process>();

            foreach (FileInfo filename in filenames)
            {
                Process[] aProcess = Process.GetProcessesByName(filename.Name.Replace(filename.Extension, ""));

                foreach (Process proc in aProcess)
                {
                    try
                    {
                        //are one of the exe's in baseDir running?
                        if (proc.MainModule != null && string.Equals(proc.MainModule.FileName, filename.FullName, StringComparison.OrdinalIgnoreCase)

                            //if the running process is not this wyUpdate instance
                            && !InstallUpdate.ProcessIsSelf(proc.MainModule.FileName))
                        {
                            rProcs.Add(proc);
                        }
                    }
                    catch { }
                }
            }

            // remove any closed processes
            for (int i = 0; i < rProcs.Count; i++)
            {
                if (rProcs[i].HasExited)
                {
                    rProcs.RemoveAt(i);
                    i--;
                }
            }

            e.Result = rProcs.Count > 0 ? rProcs : null;
        }
Пример #2
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            List <Process> list = new List <Process>();

            foreach (FileInfo filename in filenames)
            {
                Process[] processesByName = Process.GetProcessesByName(filename.Name.Replace(filename.Extension, ""));
                Process[] array           = processesByName;
                foreach (Process process in array)
                {
                    try
                    {
                        if (process.MainModule != null && string.Equals(process.MainModule.FileName, filename.FullName, StringComparison.OrdinalIgnoreCase) && !InstallUpdate.ProcessIsSelf(process.MainModule.FileName))
                        {
                            list.Add(process);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                if (list[j].HasExited)
                {
                    list.RemoveAt(j);
                    j--;
                }
            }
            e.Result = ((list.Count > 0) ? list : null);
        }