Example #1
0
        static void Main(string[] args)
        {
            Job job = new Job("pro", 1);

            Console.WriteLine("My processes was opened");
            Process.Start("notepad");
            Process.Start("word");
            job.AddProcessToJob(Process.GetProcessesByName("notepad")[0]);
            job.AddProcessToJob(Process.GetProcessesByName("word")[0]);

            Console.WriteLine("For kill the processes, press Enter . . .");
            Console.ReadLine();
            job.Kill();


            Console.WriteLine("To create new processes, press Enter . . .");
            Console.ReadLine();
            for (int i = 0; i < 20; i++)
            {
                new Job(1);
            }

            for (int i = 0; i < 20; i++)
            {
                new Job(10485760);
            }

            //size have to be positive number bigger than zero

            //for (int i = 0; i < 20; i++)
            //{
            //    new Job(0);
            //}
        }
        static void Main(string[] args)
        {
            Job job = new Job();

            try
            {
                job.AddProcessToJob(Process.Start("notepad.exe"));
                job.AddProcessToJob(Process.Start("calc.exe"));
            }
            catch (Win32Exception ex)
            {
                Trace.TraceError(ex.Message);
                Console.WriteLine("Given process not exist");
            }
            catch (InvalidOperationException ex)
            {
                Trace.TraceError(ex.Message);
            }


            Console.WriteLine("Press Enter to close the job...");
            Console.ReadLine();
            job.Kill();

            for (int i = 0; i < 20; i++)
            {
                job = new Job(100);
            }
        }
Example #3
0
        public void Run()
        {
            Job     firstJob    = new Job();
            Process calcProcess = Process.Start("calc");

            Debug.Assert(calcProcess != null);
            firstJob.AddProcessToJob(calcProcess);
            Process notepadProcess = Process.Start("notepad");

            Debug.Assert(notepadProcess != null);
            firstJob.AddProcessToJob(notepadProcess);
            Console.WriteLine("Press enter to kill all firstJob processes");
            Console.ReadLine();
            firstJob.Kill();

            Job[]  JobArray = new Job[20];
            string name;
            int    memorySize = 1;

            for (int i = 1; i < 21; i++)
            {
                name            = "Job " + i;
                JobArray[i - 1] = new Job(name, memorySize);
                memorySize     += 500000;
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            try
            {
                Job newJob = new Job("claculator");
                newJob.AddProcessToJob(Process.Start(new ProcessStartInfo("Notepad.exe")));
                Console.ReadLine();
                if (Console.ReadKey().Key == ConsoleKey.Enter)
                {
                    newJob.Kill();
                }
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
            }

            try
            {
                for (int i = 0; i < 20; i++)
                {
                    Job newJob = new Job(i.ToString());
                }
                Console.ReadLine();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e);
            }
        }
 static void Main(string[] args)
 {
     Job myJob = new Job("manage_resources");
     myJob.AddProcessToJob(Process.Start("notepad"));
     myJob.AddProcessToJob(Process.Start("calc"));
     Console.WriteLine("Press enter to kill the job");
     Console.ReadLine();
     myJob.Kill();
     uint count = 0;
     for (uint i = 0; i <= 20; i++)
     {
         var newJob = new Job(count);
         count += 500000;
     }
     Console.ReadLine();
 }
Example #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Part A example:");
            Console.WriteLine("**************************************************");
            try
            {
                Job job = new Job("MyJob");
                job.AddProcessToJob(Process.Start("mspaint"));
                job.AddProcessToJob(Process.Start("notepad"));

                Console.WriteLine("press enter to exit");
                Console.ReadLine();

                job.Kill();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("Part B example:");
            Console.WriteLine("**************************************************");

            try
            {
                for (int i = 0; i < 20; i++)
                {
                    var j = new Job(10485760);
                }
            }
            catch (ObjectDisposedException ex1)
            {
                Console.WriteLine(ex1.Message);
            }
            catch
            (InvalidOperationException ex2)
            {
                Console.WriteLine(ex2.Message);
            }
        }
 static void Main(string[] args)
 {
     using (Job currJob = new Job("FirstJob"))
     {
         for (int i = 0; i < 3; i++)
         {
             Process currNote = Process.Start("Notepad");
             currJob.AddProcessToJob(currNote);
         }
         Console.WriteLine("Press enter to kill all the processes");
         Console.ReadLine();
         currJob.Kill();
     }
 }
Example #8
0
        static void Main(string[] args)

        {
            // --------  A  --------
            Job job = new Job("job", 1);

            job.AddProcessToJob(Process.Start("notepad"));
            job.AddProcessToJob(Process.Start("calc"));
            Console.ReadLine();
            job.Kill();

            // --------  B  --------

            for (int i = 0; i < 20; i++)
            {
                Job job1 = new Job("work", 0);
            }

            for (int i = 0; i < 20; i++)
            {
                Job job1 = new Job("work", 1024 * 1024 * 10);
            }
        }
Example #9
0
        public void Run()
        {
            Job firstJob = new Job();
            Process calcProcess = Process.Start("calc");
            Debug.Assert(calcProcess != null);
            firstJob.AddProcessToJob(calcProcess);
            Process notepadProcess = Process.Start("notepad");
            Debug.Assert(notepadProcess != null);
            firstJob.AddProcessToJob(notepadProcess);
            Console.WriteLine("Press enter to kill all firstJob processes");
            Console.ReadLine();
            firstJob.Kill();

            Job[] JobArray = new Job[20];
            string name;
            int memorySize = 1;
            for (int i = 1; i < 21; i++)
            {
                name = "Job " + i;
                JobArray[i - 1] = new Job(name, memorySize);
                memorySize += 500000;
            }
        }
Example #10
0
        static void Main(string[] args)

        {
            // --------  A  --------
            try
            {
                Job job = new Job("job");
                job.AddProcessToJob(Process.Start("notepad"));
                job.AddProcessToJob(Process.Start("calc"));
                Console.ReadLine();
                job.Kill();
            }
            catch (ArgumentException ex) { Console.WriteLine(ex.Message); }
            catch (ObjectDisposedException ex) { Console.WriteLine(ex.ObjectName + " is disposed"); }

            // --------  B  --------

            try // will cause an exception
            {
                for (int i = 0; i < 20; i++)
                {
                    Job job1 = new Job("work", 0);
                }
            }
            catch (ArgumentException ex) { Console.WriteLine(ex.Message); }

            try
            {
                List <Job> jobs = new List <Job>();
                for (int i = 0; i < 20; i++)
                {
                    Job j = new Job("work" + i, 10 * 1024 * 1024);
                }
                Console.ReadLine();
            }
            catch (ArgumentException ex) { Console.WriteLine(ex.Message); }
        }
Example #11
0
        static void Main(string[] args)
        {
            //Part A of exercise.
            var job = new Job("MyProcesses", 1);

            Process.Start("notepad");
            Process.Start("mspaint");
            job.AddProcessToJob(Process.GetProcessesByName("notepad")[0]);
            job.AddProcessToJob(Process.GetProcessesByName("mspaint")[0]);

            Console.WriteLine("Press <Enter> key to kill processes...");
            Console.ReadLine();
            job.Kill();

            //Part B of exercise.
            Console.WriteLine("Adding 20 Job objects with 0MB additional memory:");
            var jobs = new List <Job>();

            for (int i = 0; i < 20; i++)
            {
                jobs.Add(new Job(1));
                Console.WriteLine($"Job {i} was created.");
            }
            jobs.Clear();

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Adding 20 Job objects with 10MB additional memory:");
            for (int i = 0; i < 20; i++)
            {
                jobs.Add(new Job(10485760));
                Console.WriteLine($"Job {i} was created.");
            }

            Console.WriteLine();
            Console.WriteLine("App needed to free some memory to proceed, calling GC.");
        }
Example #12
0
        static void Main(string[] args)
        {
            //6.	In the Main method, create a Job object,
            //      and assign some processes to it
            //      (Use Process.Start to create some simple processes, such as “notepad” or “calc”).

            /*
             *
             * var jobs = new Job("myJobs");
             * jobs.AddProcessToJob(Process.Start("mspaint"));
             * jobs.AddProcessToJob(Process.Start("notepad"));
             *
             * //7. Call Console.ReadLine and after the user hits <enter>
             * //  kill all processes in the job using the Kill
             * Console.ReadLine();
             * jobs.Kill();
             *
             */

            ///////////////// 8. part B /////////////////
            Random rand  = new Random();
            var    jobs2 = new List <Job>();

            // d.   Create a loop in your main method that creates 20 Job objects
            for (int i = 0; i < 20; i++)
            {
                //test the dispose pattern
                if (rand.Next(10) > 7)
                {
                    jobs2[jobs2.Count - 1].Dispose();
                    jobs2.RemoveAt(jobs2.Count - 1);
                }
                Job j = new Job($"job {i}");
                jobs2.Add(j);
                j.AddProcessToJob(Process.Start("notepad"));
            }

            //e.	See what happens when you run the application with different “sizeInBytes”.
            //      Try 0 MB and 10 MB

            Console.ReadLine();
            foreach (Job j in jobs2)
            {
                j.Kill();
            }
        }
Example #13
0
        static void Main(string[] args)
        {
            Process curProcess;

            using (Job job = new Job("a", 1))
            {
                for (int i = 0; i < 20; i++)
                {
                    curProcess = Process.Start("Notepad");
                    job.AddProcessToJob(curProcess);
                }

                Console.WriteLine("Press any key to kill the processes");
                Console.ReadLine();
                job.Kill();
            }
        }
Example #14
0
        private static void Execute(string[] args)
        {
            using (var job = new Job())
            {
                for (var i = 0; i < 4; i++)
                {
                    var p = Process.Start("notepad");
                    Debug.Assert(p != null);
                    job.AddProcessToJob(p);
                }
                Console.WriteLine("Press <Enter> to kill all notepad instances...");
                Console.ReadLine();

                job.Kill();
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();

            Console.ReadLine();
        }
Example #15
0
        static void Main(string[] args)
        {
            /// 6.
            /// In the Main method, create a Job object,
            /// and assign some processes to it
            /// (Use Process.Start to create some simple processes, such as “notepad” or “calc”).
            ///
            Job     job           = new Job();
            Process someProcesses = Process.Start("notepad");

            try
            {
                job.AddProcessToJob(someProcesses.Id);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
            }

            /// 7.
            /// Call Console.ReadLine
            /// and after the user hits<enter> kill all processes in the job using the Kill instance method.
            Console.WriteLine();
            job.Kill();

            /// B.d.  Create a loop in your main method that creates 20 Job objects
            ///e.See what happens when you run the application with different “sizeInBytes”.
            ///Try 0 MB and 10 MB

            for (int i = 0; i < 20; i++)
            {
                var j = new Job();
            }
            for (int i = 0; i < 20; i++)
            {
                var j = new Job(null, _10M);
            }

            Console.Read();
        }