Ejemplo n.º 1
0
        private void Run()
        {
            try
            {
                _isRunning = true;
                while (!_isCancel)
                {
                    try
                    {
                        _jsonConfig = JsonConfig.Factory(_url);
                        _jsonConfig.Save();
                        if (!_jsonConfig.IsNewVersion(_currentVersion))
                        {
                            Sleep(_jsonConfig.GetMilliseconds() / 1000);
                            continue;
                        }

                        if (!_jsonConfig.ForceUpdate)
                        {
                            _await = true;
                            OnNewUpdate();
                            Waiting();
                            if (!_isAccepted)
                            {
                                Sleep(_jsonConfig.GetMilliseconds() / 1000);
                                continue;
                            }
                        }

                        _progress = 0;
                        _jsonConfig.ProgressChanged   += (e, a) => OnDownloadProgressChanged(a);
                        _jsonConfig.DownloadCompleted += (e, a) => OnDownloadCompleted();
                        _await = true;
                        _jsonConfig.Download();
                        Waiting();
                        if (_progress != 100)
                        {
                            continue;
                        }
                        _isCancel = true;
                    }
                    catch (DnsNotResolveException ex)
                    {
                        Sleep(_jsonConfig.GetMilliseconds() / 1000);
                        OnError(ex.Message);
                    }
                    catch (ProtocolErrorException ex)
                    {
                        Sleep(_jsonConfig.GetMilliseconds() / 1000);
                        OnError(ex.Message);
                    }
                    catch (ConnectionFailureException ex)
                    {
                        Sleep(_jsonConfig.GetMilliseconds() / 1000);
                        OnError(ex.Message);
                    }
                    catch (Exception ex)
                    {
                        Sleep(_jsonConfig.GetMilliseconds() / 1000);
                        OnError(ex.Message);
                    }
                }
            }
            catch (ThreadAbortException)
            {
                _isRunning = false;
            }
            catch (ThreadInterruptedException)
            {
                _isRunning = false;
            }
            _isRunning = false;
        }