Example #1
0
        public static void SaveOwnedProcesses(IEnumerable<Process> processes, string fileName)
        {
            if (File.Exists(fileName))
                File.Delete(fileName);
            Directory.CreateDirectory(Path.GetDirectoryName(fileName));

            List<OwnedProcess> children = new List<OwnedProcess>();
            foreach (Process process in processes)
            {
                try
                {
                    OwnedProcess child = new OwnedProcess()
                    {
                        Id = process.Id,
                        //no SessionId on Unix
                        SessionId = OSVersionPlatform.GetGenericPlatform() == System.PlatformID.Unix ? 0 : process.SessionId,
                        Name = process.ProcessName
                    };
                    children.Add(child);
                }
                catch (InvalidOperationException)
                {
                    //System.InvalidOperationException: Process has exited, so the requested information is not available.
                    //e.g. closing the application while SaveOwnedProcesses() is running
                }
            }
            ConfigurationReaderWriter.WriteConfiguration(children, fileName);
        }
        public static void SaveOwnedProcesses(IEnumerable <Process> processes, string fileName)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            Directory.CreateDirectory(Path.GetDirectoryName(fileName));

            List <OwnedProcess> children = new List <OwnedProcess>();

            foreach (Process process in processes)
            {
                try
                {
                    OwnedProcess child = new OwnedProcess()
                    {
                        Id = process.Id,
                        //no SessionId on Unix
                        SessionId = OSVersionPlatform.GetGenericPlatform() == System.PlatformID.Unix ? 0 : process.SessionId,
                        Name      = process.ProcessName
                    };
                    children.Add(child);
                }
                catch (InvalidOperationException)
                {
                    //System.InvalidOperationException: Process has exited, so the requested information is not available.
                    //e.g. closing the application while SaveOwnedProcesses() is running
                }
            }
            ConfigurationReaderWriter.WriteConfiguration(children, fileName);
        }