예제 #1
0
 public void DealPacket_Finish(object pack)
 {
     if (state.workMode == CState.WorkMode.ReplayMode)
     {
         if (this.state.isSceneSetUp == false)//因为确定是主线程才会调用此函数所以不用锁
         {
             return;
         }
         this.toolStripStatusLabel4.Text = "回放完成";
         this.root.Pause();
         WaitForm waitForm = new WaitForm();
         waitForm.Text = "回放结束,是否重启";
         waitForm.ShowDialog();
         if (waitForm.buttonClicked.Equals("buttonYes"))
         {
             ResetCloseScene();
         }
     }
     else if (state.workMode == CState.WorkMode.SimMode)
     {
         root.Pause();
         toolStripStatusLabel4.Text = "仿真完成";
         timer2.Enabled             = false;
         WaitForm waitForm = new WaitForm();
         waitForm.Text = "是否保存数据";
         waitForm.ShowDialog();
         if (waitForm.buttonClicked.Equals("buttonYes"))
         {
             RdXml.InitXmlWriter();
             RdXml.SaveXmlWriter();
             MessageBox.Show("保存成功!");
         }
         waitForm.Dispose();
         RdXml.ResetXmlWriter();
         display("仿真结束");
     }
     if (静态链路ToolStripMenuItem.Checked)
     {
         ehelper.end();
     }
 }
예제 #2
0
        public void ResetCloseScene()
        {
            //0725添加新的excel处理,上次的还有问题
            string res;

            CmdHelper.RunCmd("taskkill /f /im excel.exe", out res);
            if (this.state.isSceneSetUp == false) //isScenesetup说明rdxml清理过
            {
                if (root.CurrentScenario != null) //20150907
                {
                    state.isSceneSetUp = false;   //STK仿真场景是否已建立
                    CloseScene();
                }
                return;
            }

            DateTime start = DateTime.Now;
            //LogHelper.InfoLog("ResetCloseScene", "进入函数");
            TimeSpan tSpan = DateTime.Now - start;//中间的时间差是执行Loghelper的时间

            this.root.Pause();
            this.Cursor = Cursors.WaitCursor;

            //RdXml
            if (this.RdXml.xmlReaderThread != null)
            {
                if ((this.RdXml.xmlReaderThread.ThreadState & System.Threading.ThreadState.Stopped) == System.Threading.ThreadState.Stopped)
                {
                    //Application.DoEvents();
                    //LogHelper.InfoLog("xmlReaderThread", "已关闭");
                }
                else
                {
                    lock (this.RdXml.stopRead)
                    {
                        if (this.RdXml.isStopRead == false) //在主线程中修改使子线程自然退出
                        {
                            this.RdXml.isStopRead = true;
                        }
                    }
                    start = DateTime.Now;
                    while (true)
                    {
                        lock (this.RdXml.stopRead)
                        {
                            //Thread对象的ThreadState属性提供一个由ThreadState定义的位掩码,它指示线程的当前状态。一个线程至少总是处于ThreadState枚举中定义的一个可能状态,并且可以同时处于多个状态。
                            //1&1 =1; 结果是不变的才对.
                            if (this.RdXml.isStopRead == false)
                            {
                                //Application.DoEvents();
                                break;
                            }
                            else if ((this.RdXml.xmlReaderThread.ThreadState & System.Threading.ThreadState.Stopped) == System.Threading.ThreadState.Stopped)
                            {
                                this.RdXml.isStopRead = false;
                                //Application.DoEvents();
                                break;
                            }
                            else if ((this.RdXml.xmlReaderThread.ThreadState & System.Threading.ThreadState.WaitSleepJoin) == System.Threading.ThreadState.WaitSleepJoin)
                            {
                                try
                                {
                                    this.RdXml.xmlReaderThread.Interrupt();//唤醒之并忽略报的异常
                                }
                                catch (System.Threading.ThreadInterruptedException)
                                {
                                }
                            }
                        }
                        Application.DoEvents(); //清空当前的消息队列,防止子线程发出的更新控件消息在控件回收后才处理
                        System.Threading.Thread.Sleep(100);
                        //强制退出机制
                        tSpan = DateTime.Now - start;
                        if (tSpan.TotalMinutes > 1)
                        {
                            WaitForm waitForm = new WaitForm();
                            waitForm.Text = "关闭场景超时,是否退出软件";
                            waitForm.ShowDialog();
                            if (waitForm.buttonClicked.Equals("buttonYes"))
                            {
                                Application.Exit();
                            }
                            else
                            {
                                start = DateTime.Now;
                            }
                        }
                    }
                }
            }
            Application.DoEvents();
            if (this.state.isSceneSetUp == true)
            {
                state.isSceneSetUp = false;//STK仿真场景是否已建立
                CloseScene();
            }

            //STK仿真场景Lev1的全部obj,例如卫星、实体等
            Scenemana.stkObjs.Clear();
            Scenemana.sensorcolor_index = 0;
            Scenemana.all_path.Clear();
            Scenemana.LineTargets.Clear();

            this.RdXml.allPackets.Clear();
            this.RdXml.sw.Reset();
            try
            {
                //Other Form
                chartView.Dispose();
                chartView = new ChartView();
                chartView.Hide();
                trafficView.Dispose();
                trafficView = new TrafficView();
                trafficView.Hide();
            }
            catch
            {
            }
            System.Threading.Thread.Sleep(100);
            this.toolStripStatusLabel2.Text = "场景名";
            this.toolStripStatusLabel4.Text = "未开始";
            state.replayDataFaster          = 1;
            toolStripStatusLabel5.Text      = "x" + state.replayDataFaster.ToString();

            this.Cursor = Cursors.Default;
        }