Exemplo n.º 1
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);
        }