コード例 #1
0
 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;
     }
 }
コード例 #2
0
ファイル: Filter.cs プロジェクト: bosh/DayZCommander
 private void PublishTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
 {
     _publishTimer.Stop();
     Execute.OnUiThread(() =>
     {
         App.Events.Publish(new FilterUpdated(s => FilterHandler(s)));
     });
 }
コード例 #3
0
 private void RefreshAllBatchOnRefreshAllComplete()
 {
     RefreshAllBatch.RefreshAllComplete -= RefreshAllBatchOnRefreshAllComplete;
     _isRunningRefreshBatch              = false;
     Execute.OnUiThread(() =>
     {
         App.Events.Publish(new RefreshingServersChange(false));
     });
 }
コード例 #4
0
ファイル: ServerList.cs プロジェクト: Gaz492/DayZCommander
 public void GetAll(Action uiThreadOnComplete)
 {
     DownloadingServerList = true;
     new Thread(() =>
     {
         var servers = GetAllSync();
         Execute.OnUiThread(() =>
         {
             Items = new ObservableCollection <Server>(servers);
             DownloadingServerList = false;
             uiThreadOnComplete();
         });
     }).Start();
 }
コード例 #5
0
ファイル: ServerList.cs プロジェクト: Gaz492/DayZCommander
        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();
        }
コード例 #6
0
        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);
        }