private async Task AddNewBulb(string lampId, string lampName) { DisplayLamp lamp = BulbManager.Instance.GetLamp(lampId, lampName); if (lamp == null) { return; } DisplayLampViewModel lampViewModel = new DisplayLampViewModel(lampId, lampName); var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher; await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { this.Bulbs.Add(lampViewModel); }); }
private async void BulbManager_LampUpdated(object sender, LampUpdatedEventArgs e) { await bulbViewModelLock.WaitAsync(); try { DisplayLampViewModel found = this.Bulbs.FirstOrDefault(b => b.ID == e.AppId && b.Name == e.DeviceName); if (found != null) { await found.Update(); return; } await AddNewBulb(e.AppId, e.DeviceName); } finally { bulbViewModelLock.Release(); } }