public void NotifyPropertyChanged(params string[] changedProperties) { if (changedProperties != null) { foreach (string property in changedProperties) { InvokeHelper.Invoke(() => { OnPropertyChanged(property); }); } } }
public void Append(SensorItem e) { try { InvokeHelper.Invoke(() => { Value = e; History.Add(e); ValueChanged?.Invoke(e); NotifyPropertyChanged("History"); }); } catch (Exception x) { Debug.WriteLine(x); } }
public static Task <T> BeginInvokeOnMainThreadAsync <T>(Func <T> a) { var tcs = new TaskCompletionSource <T>(); InvokeHelper.Invoke(() => { try { var result = a(); tcs.SetResult(result); } catch (Exception ex) { tcs.SetException(ex); } }); return(tcs.Task); }
public void Append(SensorItem e) { try { InvokeHelper.Invoke(() => { Value = e; History.Add(e); ValueChanged?.Invoke(e); NotifyPropertyChanged("History"); NotifyPropertyChanged("LastSummary"); NotifyPropertyChanged("LastDribble"); NotifyPropertyChanged("DribbleHistory"); }); Task.Run(() => PostToApi(this, e)); } catch (Exception x) { Debug.WriteLine(x); } }
async Task AddSensor(IDevice device) { if (isAddingSensor) { return; } isAddingSensor = true; try { SensorModel sensor = null; sensor = await SensorKitExtensions.BeginInvokeOnMainThreadAsync <SensorModel>(() => { sensor = new SensorModel() { Id = device.Id, Name = device.Name, Information = Registry.Public.FirstOrDefault(s => s.Model == SensorInformation.TryParseSensorType(device.Name)), IsLive = true }; Data.Add(sensor); return(sensor); }); if (sensor != null) { InvokeHelper.Invoke(() => { NotifyPropertyChanged("Data"); }); } }catch (Exception x) { Debug.WriteLine(x); } isAddingSensor = false; }