示例#1
0
        public static void Comment(List <ProgramProcess> processlist)
        {
            Console.WriteLine("PID of attribute: ");
            int            searchPID       = Int32.Parse(Console.ReadLine());
            ProgramProcess searchedProcess = null;

            foreach (ProgramProcess item in processlist)
            {
                if (item.PID == searchPID)
                {
                    searchedProcess = item;
                }
            }

            if (searchedProcess == null)
            {
                Console.WriteLine("No such process, invalid ID: " + searchPID);
            }
            else
            {
                Console.WriteLine("Type comment you would like to add: ");
                string comment = Console.ReadLine();
                searchedProcess.Comment = comment;
            }
        }
示例#2
0
        public static void ListProcesses()
        {
            List <ProgramProcess> processlist = new List <ProgramProcess>();

            foreach (var proc in Process.GetProcesses())
            {
                try
                {                                           //CPU usage MISSING
                    ProgramProcess p = new ProgramProcess(proc.ProcessName, proc.Id);
                    processlist.Add(p);
                    Console.WriteLine("INFO: Name:{0}, PID:{1}", proc.ProcessName, proc.Id);
                }
                catch (System.ComponentModel.Win32Exception)
                {
                    Console.WriteLine("Acess Denied!");
                }
            }



            //////////////////////////////////////////////////////////////////////
            XmlSerializer serializer = new XmlSerializer(typeof
                                                         (List <ProgramProcess>));

            using (TextWriter tw = new StreamWriter("CD1.xml"))
            {
                serializer.Serialize(tw, processlist);
            }

            Console.WriteLine("//////////////////");

            List <ProgramProcess> deserializedProcesses = new List <ProgramProcess>();

            using (FileStream destream = File.OpenRead("CD1.xml"))
            {
                deserializedProcesses = (List <ProgramProcess>)serializer.Deserialize(destream);
            }

            foreach (var item in deserializedProcesses) //PID+Name
            {
                Console.WriteLine("INFO: Name:{0}, PID:{1}", item.Name, item.PID);
            }
        }