private void TimerProc(Object source, ElapsedEventArgs ea) { theTimer.Enabled = false; try { HttpWebRequest request = WebRequest.Create(theURL) as HttpWebRequest; request.Timeout = theRequestTimeout; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { throw new Exception(String.Format( "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); } DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(ShotclockResponse)); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); ShotclockResponse jsonResponse = objResponse as ShotclockResponse; theDispatcher.BeginInvoke(DispatcherPriority.Send, theDelegate, jsonResponse); } } catch (Exception e) { Logger.Log("Error retrieving data: " + e.Message, EventLogEntryType.Error, Logger.Type.RetrieveFailure); theDispatcher.BeginInvoke(DispatcherPriority.Send, theDelegate, null); } theTimer.Enabled = true; }
private void Update(ShotclockResponse aResponse) { if ( aResponse != null && aResponse.Status == "OK" ) { Shotclock.Text = String.Format("{0:00}", aResponse.Time); if (aResponse.Time <= theAttentionTime) { Shotclock.Fill = new SolidColorBrush(Colors.Yellow); } else { Shotclock.Fill = new SolidColorBrush(Colors.White); } } else { Shotclock.Text = "-"; } theUrl = URL.Text; }