예제 #1
0
 /// <summary>
 /// Stop is called while simulation is running.  The "running" thread is blocking on "Run", and when
 /// "stopSim" is called it will eventually exit.  The only valid "runStatus" values are STOPPED and STOP_FAILED.
 /// This monitor thread waits for the exit to happen and returns the
 /// runStatus.  If this runStatus is not normal, terminate may need to be called to clean up stray processes.
 /// </summary>
 /// <returns></returns>
 public bool Stop()
 {
     sinter.sinter_InteractiveSim isim = ((sinter.sinter_InteractiveSim)sim);
     isim.stopSim();
     // Wait for Stop to work
     // According to developer this will always return
     Debug.WriteLine("Waiting for Stop", this.GetType().Name);
     lock (this)
     {
         Debug.WriteLine(String.Format("sim.ruStatus {0}", sim.runStatus), this.GetType().Name);
         if (sim.runStatus == sinter.sinter_AppError.si_SIMULATION_STOPPED)
         {
             return(true);
         }
         else if (sim.runStatus == sinter.sinter_AppError.si_STOP_FAILED)
         {
             return(false);
         }
         else
         {
             Debug.WriteLine(String.Format("Unexpect runStatus value {0}", sim.runStatus));
             return(false);
         }
     }
     throw new InvalidOperationException(String.Format("Unexpect runStatus value {0}", sim.runStatus));
 }
예제 #2
0
        /// <summary>
        /// Stop is called while simulation is running.  The "running" thread is blocking on "Run", and when
        /// "stopSim" is called it will eventually exit.  The only valid "runStatus" values are STOPPED and STOP_FAILED.
        /// This monitor thread waits for the exit to happen and returns the
        /// runStatus.  If this runStatus is not normal, terminate may need to be called to clean up stray processes.
        /// </summary>
        /// <returns></returns>
        public bool Stop()
        {
            if (sim != null)
            {
                sinter.sinter_InteractiveSim isim = ((sinter.sinter_InteractiveSim)sim);
                sim.closeSim();

                try
                {
                    isim.stopSim();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Message: " + ex.Message, "SinterConsumerRun.Stop");
                    Debug.WriteLine("StackTrace: " + ex.StackTrace, "SinterConsumerRun.Stop");
                }

                // Wait for Stop to work
                // According to developer this will always return
                Debug.WriteLine("Waiting for Stop", this.GetType().Name);
                int wait_seconds = 60;
                if (Monitor.TryEnter(this, new TimeSpan(0, 0, wait_seconds)))
                {
                    Debug.WriteLine(String.Format("Obtained Lock, Stop simulation status: {0}", sim.runStatus), "SinterConsumerRun.Stop");
                    Monitor.Exit(this);
                    return(sim.runStatus == sinter.sinter_AppError.si_SIMULATION_STOPPED);
                }
            }

            // NEVER GOT LOCK
            Debug.WriteLine(String.Format("Failure to Obtain Lock"), "SinterConsumerRun.Stop");
            return(false);
        }