using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace VersionUpdate { public partial class DownloadForm : Form { List updateClass; Client client; public DownloadForm(List updateClass, Client client) { InitializeComponent(); this.updateClass = updateClass; this.client = client; } public bool IsOk = false; Thread thread; private void button1_Click(object sender, EventArgs e) { try { this.button1.Enabled = false; thread = new Thread(new ThreadStart(delegate { try { client.DownFile(updateClass, this.progressBar1, this.label1); IsOk = true; this.Invoke(new Action(delegate { this.Close(); })); } catch (Exception ex) { this.Invoke(new Action(delegate { MessageBox.Show(ex.Message, "下载失败", MessageBoxButtons.OK, MessageBoxIcon.Error); })); } })); thread.IsBackground = true; thread.Start(); } catch (Exception ex) { } } private void DownloadForm_Load(object sender, EventArgs e) { try { StringBuilder sb = new StringBuilder(); foreach (var item in updateClass) { sb.Append($"{item.Name} -- {item.Version}\r\n"); for (int i = 0; i < item.Message.Count; i++) { sb.AppendLine($"{i + 1}、{item.Message[i]}"); } sb.AppendLine(""); sb.AppendLine(""); } this.richTextBox1.Text = sb.ToString().Trim(); } catch (Exception ex) { } } private void DownloadForm_FormClosing(object sender, FormClosingEventArgs e) { try { if (thread != null && !IsOk) { try { thread.Abort(); } catch (Exception ex1) { } } } catch (Exception ex) { } } } }