// Timer Callback public void UpdateRelays(object state) { using (HttpClient httpClient = new HttpClient()) { for (int x = 0; x < Relays.Count(); x++) { string relayUrl = string.Format("{0}/settings/relay/{1}", deviceUrl, x); var httpResponse = httpClient.GetStringAsync(relayUrl).Result; Relay rel = JsonConvert.DeserializeObject <Relay>(httpResponse); List <Variance> variances = rel.DetailedCompare(Relays[x]); variances.ForEach(variance => { Console.WriteLine("Property {0} changed from {1} to {2}.", variance.Prop, variance.valB, variance.valA); if (variance.valA != null && variance.valB != null) { Relays[x].GetType().GetProperty(variance.Prop).SetValue(Relays[x], variance.valA); if (variance.Prop.Equals("Ison")) { RelaySwitched?.Invoke(this, new DeviceSwitchedEventArgs { Device = this, IsOn = rel.Ison }); } } }); /* * if (rel.Ison != Relays[x].Ison) * { * * Relays[x].Ison = rel.Ison; * } */ // Relays[x] = rel; Relays[x].Parent = this; Relays[x].Id = x; } } }