public void CloseFG() { this.fgAdapter?.Close(true); this.IsPaused = true; this.fgAdapter = null; NotifyPropertyChanged("IsPowerOn"); }
// if there is no yet simulator, open one and establish connection (in diffrent thread). // start the playing = timestep increasment in timer public void Play() { if (timer == null || fgAdapter == null || ts == null) { timer = new Timer(); timer.Elapsed += delegate(object sender, ElapsedEventArgs e) { this.CurrentTimeStep++; }; fgAdapter = new FgAdapter(new FileDetails(this.FG_Path).OnlyPath); this.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "CurrentTimeStep" && ts != null) { this.fgAdapter?.SendPlayback(ts.getRowAsString(CurrentTimeStep)); } }; fgAdapter.OnFGClosing += delegate() { // DONT ADD IsPaused = true this.fgAdapter = null; CloseFG(); }; ts = new TableSeries(this.TestCsv_Path, Utils.ParseFeaturesLine(this.XML_Path)); // wait to the simulator to be ready, // but in diffrent thread (the waiting, the simulator is in different process) this.shouldWaitForFgAdapter = true; new System.Threading.Thread(delegate() { fgAdapter?.Start(new FileDetails(this.XML_Path).NameWithoutExtension); // [code waiting] in this new thread // DONT add IsPaused or IsRunning, to avoid infinty loop / problems with multithreads if (timer == null || fgAdapter == null || ts == null) { currTimeStep = 0; timer?.Stop(); } else { this.shouldWaitForFgAdapter = false; UpdateSpeed(); timer?.Start(); } }).Start(); NotifyPropertyChanged("MaxTimeStep", "AllFeaturesList"); NotifyPropertyChanged("IsPowerOn"); } // DONT add IsPaused or IsRunning, to avoid infinty loop / problems with multithreads if (shouldWaitForFgAdapter) { return; } UpdateSpeed(); timer?.Start(); }