using bzit.bomg.Models; using RyzStudio.Windows.Forms; using RyzStudio.Windows.ThemedForms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; using Form = System.Windows.Forms.Form; using Resources = bzit.bomg.Properties.Resources; namespace bzit.bomg { public partial class OptionForm : Form { protected BackgroundWorker threadWorker = null; protected BookmarkItemModel itemModel = null; protected MainForm parentForm = null; public OptionForm(MainForm mainForm) : base() { InitializeComponent(); parentForm = mainForm; this.StartPosition = FormStartPosition.WindowsDefaultLocation; if (threadWorker == null) { threadWorker = new BackgroundWorker(); threadWorker.WorkerReportsProgress = threadWorker.WorkerSupportsCancellation = true; threadWorker.DoWork += threadWorker1_DoWork; threadWorker.RunWorkerCompleted += threadWorker1_RunWorkerCompleted; } } protected void threadWorker1_DoWork(object sender, DoWorkEventArgs e) { if (threadWorker.CancellationPending) { return; } List nodeList = parentForm.treeView1.GetBookmarkNodeList(); ThreadControl.SetValue(progressBar1, 0, nodeList.Count); for (int i=0; i { parentForm.treeView1.UpdateItem(nodeList[i], model.ToViewModel()); })); } else { parentForm.treeView1.UpdateItem(nodeList[i], model.ToViewModel()); } } } } protected void threadWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { this.IsBusy = false; ThreadControl.SetText(button2, "&Update"); } protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); if (this.IsBusy) { e.Cancel = true; } } protected bool IsBusy { get => threadWorker.IsBusy; set { pictureBox1.Image = (value) ? Resources.aniZomq2x32 : null; } } private void button1_Click(object sender, EventArgs e) { if (this.IsBusy) { ThreadControl.SetText(button2, "&Cancelling..."); threadWorker.CancelAsync(); } else { this.IsBusy = true; ThreadControl.SetText(button2, "&Updating..."); threadWorker.RunWorkerAsync(); } } private void button2_Click(object sender, EventArgs e) { if (this.IsBusy) { return; } this.Close(); } } }