88using System . Threading ;
99using System . Windows ;
1010using System . Windows . Input ;
11- using NETworkManager . Collections ;
1211using System . ComponentModel ;
1312using System . Diagnostics ;
1413using System . Windows . Threading ;
1514using System . Windows . Data ;
1615using Dragablz ;
1716using NETworkManager . Controls ;
1817using NETworkManager . Utilities ;
18+ using System . Collections . ObjectModel ;
1919
2020namespace NETworkManager . ViewModels
2121{
@@ -30,7 +30,7 @@ public class PingViewModel : ViewModelBase
3030 Stopwatch stopwatch = new Stopwatch ( ) ;
3131
3232 private bool _isLoading = true ;
33-
33+
3434 private string _host ;
3535 public string Host
3636 {
@@ -79,8 +79,8 @@ public bool CancelPing
7979 }
8080 }
8181
82- private AsyncObservableCollection < PingInfo > _pingResult = new AsyncObservableCollection < PingInfo > ( ) ;
83- public AsyncObservableCollection < PingInfo > PingResult
82+ private ObservableCollection < PingInfo > _pingResult = new ObservableCollection < PingInfo > ( ) ;
83+ public ObservableCollection < PingInfo > PingResult
8484 {
8585 get { return _pingResult ; }
8686 set
@@ -92,6 +92,13 @@ public AsyncObservableCollection<PingInfo> PingResult
9292 }
9393 }
9494
95+ private ICollectionView _pingResultView ;
96+ public ICollectionView PingResultView
97+ {
98+ get { return _pingResultView ; }
99+ }
100+
101+
95102 private int _pingsTransmitted ;
96103 public int PingsTransmitted
97104 {
@@ -270,8 +277,12 @@ public PingViewModel(int tabId, string host)
270277 _tabId = tabId ;
271278 Host = host ;
272279
280+ // Set collection view
273281 _hostHistoryView = CollectionViewSource . GetDefaultView ( SettingsManager . Current . Ping_HostHistory ) ;
274282
283+ // Result view
284+ _pingResultView = CollectionViewSource . GetDefaultView ( PingResult ) ;
285+
275286 LoadSettings ( ) ;
276287
277288 _isLoading = false ;
@@ -455,7 +466,7 @@ private void AddHostToHistory(string host)
455466 }
456467
457468 public void OnClose ( )
458- {
469+ {
459470 // Stop the ping
460471 if ( IsPingRunning )
461472 PingAction ( ) ;
@@ -468,7 +479,10 @@ private void Ping_PingReceived(object sender, PingReceivedArgs e)
468479 PingInfo pingInfo = PingInfo . Parse ( e ) ;
469480
470481 // Add the result to the collection
471- PingResult . Add ( pingInfo ) ;
482+ Application . Current . Dispatcher . BeginInvoke ( DispatcherPriority . Normal , new Action ( delegate ( )
483+ {
484+ PingResult . Add ( pingInfo ) ;
485+ } ) ) ;
472486
473487 // Calculate statistics
474488 PingsTransmitted ++ ;
@@ -489,10 +503,10 @@ private void Ping_PingReceived(object sender, PingReceivedArgs e)
489503
490504 if ( MaximumTime < pingInfo . Time )
491505 MaximumTime = pingInfo . Time ;
492- }
493506
494- // I don't know if this can slow my application if the collection is to large
495- AverageTime = ( int ) PingResult . Average ( s => s . Time ) ;
507+ // I don't know if this can slow my application if the collection is to large
508+ AverageTime = ( int ) PingResult . Select ( s => s . Time ) . Average ( ) ;
509+ }
496510 }
497511 else
498512 {
0 commit comments