Esempio n. 1
0
        public static void ReadJobs(string filePath, ref JobScheduler scheduler)
        {
            jobReader = new StreamReader(filePath);

            while (!jobReader.EndOfStream)
            {
                scheduler.Enqueue(new Job(jobReader.ReadLine()));
            }

            jobReader.Close();
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            // Initailze the scheduler.
            js = new JobScheduler();
            
            // Set the current time to 0.
            workerTime = 0;

            // Open the job file and load the jobs
            // into the scheduler
            JobLoader.ReadJobs(OpenJobFile(), ref js);

            // Start the worker and clock threads
            RunWorker();

            Console.WriteLine("Press \'Q\' to exit.\nPRess \'S\' to pause/suspend operations.\nPress \'R\' to resume operations.");
            // Wait for keyboard input to determine an action
            ConsoleKeyInfo ki = new ConsoleKeyInfo();
            while (true)
            {
                ki = Console.ReadKey(true);
                if (ki.Key == ConsoleKey.Q)
                {
                    if (threadWorker.ThreadState == ThreadState.Suspended &&
                        threadClock.ThreadState == ThreadState.Suspended)
                    {
                        threadWorker.Resume();
                        threadClock.Resume();
                    }

                    threadWorker.Abort();
                    threadClock.Abort();
                    break;
                }

                if (ki.Key == ConsoleKey.S)
                {
                    Verbose.ThreadInfo("Suspend processing...");
                    try
                    {
                        threadWorker.Suspend();
                        threadClock.Suspend();
                        Verbose.ThreadInfo("Success.");
                    }
                    catch (Exception)
                    {
                        Verbose.ThreadInfo("Failed to suspend processing.\n" + "Threads may already be suspended.".PadLeft(7));
                    }
                }

                if (ki.Key == ConsoleKey.R)
                {
                    Verbose.ThreadInfo("Resume processing...");
                    try
                    {
                        threadWorker.Resume();
                        threadClock.Resume();
                        Verbose.ThreadInfo("Success.");
                    }
                    catch (Exception)
                    {
                        Verbose.ThreadInfo("Failed to resume processing.\n" + "Threads may already be started.".PadLeft(7));
                    }
                }
            }

            // Flush final output to the output file.
            Verbose.WriteOutputFile();

            Console.WriteLine("Exiting");
        }