Beispiel #1
0
        private void PerformUpdateCheck(bool msgBox = false)
        {
            var uc = new UpdateChecker();

            uc.AlreadyLatest += (o, e) => {
                if (msgBox)
                {
                    MessageBox.Show("You are already using the latest version available", "Already latest", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                UpdateStatus("already latest version", 100);
                Task.Delay(2000).ContinueWith(task => {
                    if (InvokeRequired && IsHandleCreated)
                    {
                        Invoke((Action) delegate { pbProgress.Visible = false; });
                    }
                });
            };
            uc.Connected += (o, e) => UpdateStatus("connected", 10);
            uc.DownloadProgressChanged += (o, e) => {             /* care, xml is small anyway */
            };
            uc.UpdateCheckFailed       += (o, e) => {
                UpdateStatus("update check failed", 100);
                if (msgBox)
                {
                    MessageBox.Show("Update check failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Task.Delay(2000).ContinueWith(task => Invoke((Action) delegate { pbProgress.Visible = false; }));
            };
            uc.UpdateAvailable += (o, e) => {
                UpdateStatus("update available", 100);

                var dr = MessageBox.Show($"An update to version {e.Version.ToString()} released on {e.ReleaseDate.ToShortDateString()} is available. Release notes: \r\n\r\n{e.ReleaseNotes}\r\n\r\nUpdate now?", "Update available", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Yes)
                {
                    DownloadAndUpdate(e.DownloadUrl);
                }
            };
            uc.CheckVersion();
        }