private void UpdateBtn_Click(object sender, EventArgs e) { if (worker == null) { UpdateBtn.Text = "Stop"; LogTxt.Text = ""; worker = new Thread(() => { try { Updater updater = new Updater(UpdateUrl, DatabaseLocation); updater.ProgressMessage += new ManicTimeMonitor.Updater.NotificationEventHandler(Updater_ProgressMessage); updater.Update(); } catch (ThreadAbortException) { // do nothing } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message); } UpdateBtn.Invoke(new Action(() => UpdateBtn.Text = "Update now")); worker = null; }); worker.Start(); } else { worker.Abort(); worker = null; UpdateBtn.Text = "Update now"; LogTxt.AppendText("Stopped"); } }
void Updater_ProgressMessage(string message) { UpdateBtn.Invoke(new Action(() => LogTxt.AppendText("[" + DateTime.Now + "] " + message + "\r\n"))); }