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(TimeclockResponse)); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); TimeclockResponse jsonResponse = objResponse as TimeclockResponse; 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 TimeclockUpdate(TimeclockResponse aResponse) { if (aResponse != null && aResponse.Status == "OK") { Timeclock.Text = String.Format("{0}", aResponse.Minute) + ":" + String.Format("{0:00}", aResponse.Second); } else { Timeclock.Text = "-"; } }