/// <summary>Initialise the shell.</summary> /// <param name="contentFrame">The frame insided the shell used for most navigations.</param> public ShellViewModel(Frame contentFrame) { _contentFrame = contentFrame; IsInternetAvailable = Request.IsInternetAvailable(); UpdateInternetInViewModels(IsInternetAvailable); _internetCheckTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(5) }; _internetCheckTimer.Tick += OnInternetCheckTimerTick; DispatcherTimers.Add(_internetCheckTimer); _internetCheckTimer.Start(); _syncTimer = new DispatcherTimer { Interval = TimeSpan.FromMinutes(1) }; _syncTimer.Tick += OnSyncTimerTick; DispatcherTimers.Add(_syncTimer); _syncTimer.Start(); _updateAction = async s => await Update(); BroadcasterService.Instance.NewDeviceDetected.Subscribe(_updateAction); BroadcasterService.Instance.TablesChanged.Subscribe(_updateAction); _localNetworkConflictAction = s => NavToSettingsView(); BroadcasterService.Instance.LocalNetworkConflict.Subscribe(_localNetworkConflictAction); }
public override DispatcherTimer Create(DeterministicRandom random) { //DispatcherTimer timer = null; DispatcherPriority priority = ChooseValidPriority(PriorityValue); switch (DispatcherTimerConstructorType % 4) { case 0: timer = new DispatcherTimer(); timer.Tick += new EventHandler(DispatcherTimerTick); timer.Interval = TimeSpan; break; case 1: timer = new DispatcherTimer(priority); timer.Tick += new EventHandler(DispatcherTimerTick); timer.Interval = TimeSpan; break; case 2: timer = new DispatcherTimer(priority, Dispatcher); timer.Tick += new EventHandler(DispatcherTimerTick); timer.Interval = TimeSpan; break; case 3: timer = new DispatcherTimer(TimeSpan, priority, new EventHandler(DispatcherTimerTick), Dispatcher); break; } //Save the DispatcherTimer, Some combinations of actions need do on the same DispatcherTimer. lock (DispatcherTimers) { DispatcherTimers.Add(timer); if (DispatcherTimers.Count > 10) { int removeIndex = random.Next(DispatcherTimers.Count); DispatcherTimer removeTimer = DispatcherTimers[removeIndex]; //Stop the DispatcherTimer before remove it. removeTimer.Stop(); DispatcherTimers.Remove(removeTimer); } return(DispatcherTimers[random.Next(DispatcherTimers.Count)]); } }
public LiveCardViewModel(Sensor poco) { Id = poco.ID; Placement = poco.SensorType.Place.Name; PlacementId = poco.SensorType.PlaceID; ParameterID = poco.SensorType.ParamID; SensorTypeID = poco.SensorTypeID; _dispatcher = ((App)Application.Current).Dispatcher; if (_dispatcher == null) { LoggingService.LogInfo($"Messenger.Instance.Dispatcher null at LiveCardViewModel ctor.", Windows.Foundation.Diagnostics.LoggingLevel.Error); } _dataUpdater = async readings => { var ofThisSensor = readings.Where(r => r.SensorId == poco.ID).ToList(); if (ofThisSensor.Any()) { var mostRecent = ofThisSensor.MaxBy(r => r.Timestamp); await _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => UpdateValueAndAgeStatusIfNew(mostRecent.Value, mostRecent.Timestamp)); } }; _ageStatusUpdateTime = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; _ageStatusUpdateTime.Tick += AgeStatusUpdateTimeOnTick; _ageStatusUpdateTime.Start(); DispatcherTimers.Add(_ageStatusUpdateTime); BroadcasterService.Instance.NewSensorDataPoint.Subscribe(_dataUpdater); Update(poco); var senVals = DataService.QueryMostRecentSensorValue(poco); if (null != senVals) { UpdateValueAndAgeStatusIfNew(senVals.Item1, senVals.Item2); } }
public SettingsViewModel() { _localNetworkConflictAction = LocalNetworkConflictDetected; Messenger.Instance.LocalNetworkConflict.Subscribe(_localNetworkConflictAction); var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) }; EventHandler <object> timerOnTick = (sender, o) => { var now = DateTimeOffset.Now; var diff = now - _lastConflictDetected; IsNetworkConflict = diff < TimeSpan.FromSeconds(UDPMessaging.BroadcastIntervalSeconds + 1); }; timer.Tick += timerOnTick; DispatcherTimers.Add(timer); timerOnTick.Invoke(null, null); timer.Start(); }