Browse Source

1、fixed simulator memory overflow bug

chenkui 1 year ago
parent
commit
022b90d66b

+ 17 - 6
Venus/Framework/Common/MVVM/TimerViewModelBase.cs

@@ -16,12 +16,13 @@ namespace Aitex.Core.UI.MVVM
 	{
         PeriodicJob _timer;
 
-        static List<TimerViewModelBase> _lstAll = new List<TimerViewModelBase>();
+        //static List<TimerViewModelBase> _lstAll = new List<TimerViewModelBase>();
 
+        protected bool _isStart = false;
         public static void StopAll()
         {
-            foreach (TimerViewModelBase vm in _lstAll)  
-                vm.Stop();
+            //foreach (TimerViewModelBase vm in _lstAll)  
+            //    vm.Stop();
         }
 
 
@@ -29,7 +30,7 @@ namespace Aitex.Core.UI.MVVM
         {
             _timer = new PeriodicJob(1000, this.OnTimer, "UIUpdaterThread - " + name, false, true);
 
-            _lstAll.Add(this);
+            //_lstAll.Add(this);
         }
 
         //
@@ -50,12 +51,14 @@ namespace Aitex.Core.UI.MVVM
         public void Start()
         {
             _timer.Start();
+            _isStart = true;
         }
 
 
         public void Stop()
         {
             _timer.Stop();
+            _isStart = false;
         }
 
         public void Dispose()
@@ -69,8 +72,16 @@ namespace Aitex.Core.UI.MVVM
 
         public virtual void EnableTimer(bool enable)
         {
-            if (enable) _timer.Start();
-            else _timer.Pause();
+            if (enable)
+            {
+                _timer.Start();
+                _isStart = true;
+            }
+            else
+            {
+                _timer.Pause();
+                _isStart = false;
+            }
         }
     }
 

+ 4 - 2
Venus/Framework/SimulatorCore/Commons/SerialPortDeviceViewModel.cs

@@ -117,7 +117,6 @@ namespace MECF.Framework.Simulator.Core.Commons
                     //TransactionLogItems = new ObservableCollection<TransactionLogItem>(TransactionLogItems.Skip(1).Take(maxItemNumber).ToList());
                     TransactionLogItems.Clear();
                 }
-                InvokePropertyChanged();
             }));
         }
 
@@ -131,12 +130,15 @@ namespace MECF.Framework.Simulator.Core.Commons
                     TransactionLogItems.Clear();
                     //TransactionLogItems = new ObservableCollection<TransactionLogItem>(TransactionLogItems.Skip(1).Take(maxItemNumber).ToList());
                 }
-                InvokePropertyChanged();
             }));
         }
 
         protected override void Poll()
         {
+            Application.Current.Dispatcher.Invoke(new Action(() =>
+            {
+                InvokeAllPropertyChanged();
+            }));
         }
     }
 }

+ 4 - 3
Venus/Framework/SimulatorCore/Commons/SocketDeviceViewModel.cs

@@ -111,7 +111,6 @@ namespace MECF.Framework.Simulator.Core.Commons
                 if (TransactionLogItems.Count > maxItemNumber)
                     //TransactionLogItems = new ObservableCollection<TransactionLogItem>(TransactionLogItems.Skip(1).Take(maxItemNumber).ToList());
                     TransactionLogItems.Clear();
-                InvokeAllPropertyChanged();
             }));
         }
 
@@ -123,13 +122,15 @@ namespace MECF.Framework.Simulator.Core.Commons
                 if (TransactionLogItems.Count > maxItemNumber)
                     //TransactionLogItems = new ObservableCollection<TransactionLogItem>(TransactionLogItems.Skip(1).Take(maxItemNumber).ToList());
                     TransactionLogItems.Clear();
-                InvokeAllPropertyChanged();
             }));
         }
 
         protected override void Poll()
         {
-            
+            Application.Current.Dispatcher.Invoke(new Action(() =>
+            {
+                InvokeAllPropertyChanged();
+            }));
         }
     }
 }

+ 1 - 1
Venus/Venus_Simulator/Devices/AdTecMatchMock.cs

@@ -34,7 +34,7 @@ namespace Venus_Simulator.Devices
                 sRes = "S34000C0000000000000080020015A273B00700700400005C095210";
             }
 
-            Thread.Sleep(2 * 1000);
+            //Thread.Sleep(2 * 1000);
             OnWriteMessage(sRes + "\r");
         }
     }

+ 1 - 1
Venus/Venus_Simulator/Devices/AdTecMatchMockPMB.cs

@@ -34,7 +34,7 @@ namespace Venus_Simulator.Devices
                 sRes = "S34000C0000000000000080020015A273B00700700400005C095210";
             }
 
-            Thread.Sleep(2 * 1000);
+            //Thread.Sleep(2 * 1000);
             OnWriteMessage(sRes + "\r");
         }
     }

+ 1 - 1
Venus/Venus_Simulator/Devices/AdTecMatchMockPMD.cs

@@ -34,7 +34,7 @@ namespace Venus_Simulator.Devices
                 sRes = "S34000C0000000000000080020015A273B00700700400005C095210";
             }
 
-            Thread.Sleep(2 * 1000);
+            //Thread.Sleep(2 * 1000);
             OnWriteMessage(sRes + "\r");
         }
     }