コード例 #1
0
        private void BeginProcess(RoundRobin model, Thread modelThread)
        {
            try
            {
                // Below method check whether process is initialized
                if (model.getIsInitialized())
                {
                    // Normally, thread goes to stopped state when finishes its job.
                    //Checking if thread state is stopped and process is incomplete
                    if (modelThread.ThreadState != ThreadState.Stopped && !model.IsProcessComplete())
                    {
                        if (modelThread.ThreadState == ThreadState.Suspended)
                        {
                            Console.WriteLine("Thread of file " + model.getFileName() + " is resuming ");
                            modelThread.Resume();
                            Console.WriteLine("Thread of file " + model.getFileName() + " is resumed");
                        }
                        else if (modelThread.ThreadState == ThreadState.Unstarted)
                        {
                            Console.WriteLine("Thread of file " + model.getFileName() + " is starting ");
                            modelThread.Start();
                            Console.WriteLine("Thread of file " + model.getFileName() + " is started");
                        }

                        //If thread does not finish its task within specific time quantum (1 millisecond) then suspend current thread.
                        if (!modelThread.Join(TimeSpan.FromMilliseconds(model.getTimeQuantum())))
                        {
                            if (model.IsProcessComplete() == false && modelThread.ThreadState == ThreadState.Running)
                            {
                                model.SetProcessComplete(false);
                                modelThread.Suspend();
                            }
                        }
                        else
                        {
                            //else thread is able to finish its task withing specific quantum so set process to complete
                            model.SetProcessComplete(true);
                        }
                    }
                }
            }
            catch (Exception ex) { model.SetProcessComplete(true); }
        }
コード例 #2
0
 private void IsJobLeft(RoundRobin model, Thread modelThread, Queue <RoundRobin> queueOfModel, Queue <Thread> queueOfThreads)
 {
     // We are checking if we have done our time sliced job, but yet, we are not completely done (we need more time slices)
     // Putting the model at the end of model queue, also put the Model Thread which handle our model at the end of  ModelThreads queue.
     if (model.getIsInitialized() && !model.IsProcessComplete())
     {
         queueOfModel.Enqueue(model);
         queueOfThreads.Enqueue(modelThread);
         Console.WriteLine("File writing process exceed the time quantum: " + model.getTimeQuantum() + " milliseconds, Enqueuing process of file: " + model.getFileName() + "\n");
     }
 }
コード例 #3
0
 private bool IsAllProcessComplete()
 {
     return(p1.IsProcessComplete() && p2.IsProcessComplete() && p3.IsProcessComplete() && p4.IsProcessComplete() && p5.IsProcessComplete());
 }