public void Update(int milliseconds) { new Thread( () => { // Thread.Sleep(50); lock (UpdateLock) { try { var sleepTime = milliseconds; // var items = myService.GetRecords().Select(p => p.Name); try { var sleepTime2 = sleepTime; using ( ServiceClient myService2 = new ServiceClient("BasicHttpBinding_IService", Constants.ServerAddress)) { myService2.ClientCredentials.Windows.ClientCredential.UserName = "******"; myService2.ClientCredentials.Windows.ClientCredential.Password = "******"; var customer = myService2.GetCustomerByRFID(CurrentRFID); var stations = myService2.GetAllStations(); // LocationOverview.ItemsSource = items; GoogleMaps.Locations = stations.ToArray(); this.Dispatcher.BeginInvoke( DispatcherPriority.Normal , new Action(() => { try { image = null; int BytesToRead = 100; WebRequest request = WebRequest.Create(new Uri(customer.Picture, UriKind.Absolute)); request.Timeout = -1; WebResponse response = request.GetResponse(); Stream responseStream = response.GetResponseStream(); if (responseStream != null) { var reader = new BinaryReader(responseStream); var memoryStream = new MemoryStream(); var bytebuffer = new byte[BytesToRead]; int bytesRead = reader.Read(bytebuffer, 0, BytesToRead); while (bytesRead > 0) { memoryStream.Write(bytebuffer, 0, bytesRead); bytesRead = reader.Read(bytebuffer, 0, BytesToRead); } image = new BitmapImage(); image.BeginInit(); memoryStream.Seek(0, SeekOrigin.Begin); image.StreamSource = memoryStream; } image.EndInit(); } catch (Exception) { //Default no pic pic } if (image != null && image.StreamSource.CanRead) CustomerProfile.CustomerProfilePicture.Source = image; CarInfoWidget.CarMake.Content = customer.CarMake; CarInfoWidget.CarModel.Content = customer.CarModel; CarInfoWidget. CarPlate.Content = customer.CarLicense; CustomerProfile.CustomerName.Content = (customer).Name; CustomerProfile.CustomerEmail.Content = customer.Email; CustomerProfile.CustomerPhone.Content = customer.Phone; CustomerProfile.CustomerAddress.Text = customer.Address; try { var charge = customer.ChargeRemaining; if (charge == null) charge = "0"; BatteryInfoWidget. CurrentCharge.Content = charge; BatteryInfoWidget.BatteryAnimation.PercentCharged = Convert.ToInt32(charge); BatteryInfoWidget.LastCharged.Content = customer.LastRechargeDate; BatteryInfoWidget.AccountBalance.Content = customer.AccountBalance; } catch (Exception ex) { } Dictionary<string,BitmapImage> stationlist= new Dictionary<string, BitmapImage>(); int count = 0; foreach (var stationViewModel in stations) { if(stationlist.Count>=6) break; if (stationlist.ContainsKey(stationViewModel.Name)) stationViewModel.Name = stationViewModel.Name + count; stationlist.Add(stationViewModel.Name,stationViewModel.Available?OnlineIcon:OfflineIcon); } LocationWidget.StationList.Images.ItemsSource = stationlist; // .Content = (customer).Name; NavigatePage(); })); if (_dismissTimer != null) { _dismissTimer.Stop(); _dismissTimer = null; } _dismissTimer = new System.Timers.Timer(); _dismissTimer.Elapsed += delegate { Switcher.Switch(AdvertPlayer.Instance); _dismissTimer.Stop(); }; _dismissTimer.Interval = (milliseconds); _dismissTimer.Start(); } } catch (Exception ex) { Console.WriteLine(ex.StackTrace + "\n" + ex.Message); } } catch (Exception ex) { Instance.Dispatcher.BeginInvoke( DispatcherPriority.Normal, new DispatcherOperationCallback(delegate { CustomerProfile. CustomerName.Content = "Invalid Customer"; return null; })); Console.WriteLine(ex.StackTrace + "\n" + ex.Message); ; } } }).Start(); }