public void Update(bool supressRefresh = false) { try { IsUpdating = true; var serverResult = _queryClient.Execute(); Execute.OnUiThread(() => { App.Events.Publish(new PlayersChangedEvent(Players, serverResult.Players)); Players = new ObservableCollection <Player>(serverResult.Players.OrderBy(x => x.Name)); LastException = null; Settings = serverResult.Settings; Ping = serverResult.Ping; App.Events.Publish(new ServerUpdated(this, supressRefresh)); }); } catch (Exception ex) { Execute.OnUiThread(() => { LastException = ex.Message; PropertyHasChanged("Name", "Ping"); App.Events.Publish(new ServerUpdated(this, supressRefresh)); }); } finally { IsUpdating = false; } }
private void PublishTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs) { _publishTimer.Stop(); Execute.OnUiThread(() => { App.Events.Publish(new FilterUpdated(s => FilterHandler(s))); }); }
private void RefreshAllBatchOnRefreshAllComplete() { RefreshAllBatch.RefreshAllComplete -= RefreshAllBatchOnRefreshAllComplete; _isRunningRefreshBatch = false; Execute.OnUiThread(() => { App.Events.Publish(new RefreshingServersChange(false)); }); }
public void GetAll(Action uiThreadOnComplete) { DownloadingServerList = true; new Thread(() => { var servers = GetAllSync(); Execute.OnUiThread(() => { Items = new ObservableCollection <Server>(servers); DownloadingServerList = false; uiThreadOnComplete(); }); }).Start(); }
public void UpdateAll() { if (_isUpdating) { return; } object incrementLock = new object(); _isUpdating = true; ProcessedServersCount = 0; _processed = 0; var totalCount = Items.Count; new Thread(() => { try { while (_processed <= totalCount) { Execute.OnUiThread(() => { ProcessedServersCount = _processed; }); Thread.Sleep(250); if (_processed == totalCount) { _isUpdating = false; break; } } } finally { Execute.OnUiThread(() => { ProcessedServersCount = totalCount; }); _isUpdating = false; } }).Start(); new Thread(() => { for (var index = 0; index < totalCount; index++) { var server = Items[index]; server.BeginUpdate(s => { lock (incrementLock) { _processed++; } }); Thread.Sleep(new Random().Next(5, 17)); while (index - _processed > 200) { Thread.Sleep(20); } } }).Start(); }
public void RefreshAll() { if (_isUpdating) { return; } object incrementLock = new object(); _isUpdating = true; ProcessedServersCount = 0; _processed = 0; var totalCount = _items.Count; var t = new Thread(() => { try { while (_processed <= totalCount) { Execute.OnUiThread(() => { ProcessedServersCount = _processed; }); Thread.Sleep(150); if (_processed == totalCount) { _isUpdating = false; break; } } } finally { Execute.OnUiThread(() => { ProcessedServersCount = totalCount; }); if (RefreshAllComplete != null) { RefreshAllComplete(); } _isUpdating = false; } }); t.IsBackground = true; t.Start(); var serverUpdates = _items .Select <Server, Action <Action> >(server => onComplete => server.BeginUpdate(doubleDispatchServer => { try { onComplete(); } finally { lock (incrementLock) { _processed++; } } })) .ToArray(); ServerRefreshQueue.Instance.Enqueue(serverUpdates); }