old_flsystem/类库/Update/DownloadForm.cs

99 lines
2.8 KiB
C#
Raw Normal View History

2022-09-20 03:10:29 +00:00
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 OnlineUpdate
{
public partial class DownloadForm : Form
{
List<UpdateClass> updateClass;
Client client;
public DownloadForm(List<UpdateClass> 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)
{ }
}
}
}