UpdateForm.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Windows.Forms;
  10. namespace MAutoUpdate
  11. {
  12. public partial class UpdateForm : Form
  13. {
  14. public delegate void UpdateUI(int step);//声明一个更新主线程的委托
  15. public UpdateUI UpdateUIDelegate;
  16. private UpdateWork work;
  17. public UpdateForm(UpdateWork _work)
  18. {
  19. work = _work;
  20. InitializeComponent();
  21. UpdateUIDelegate = new UpdateUI((obj) =>
  22. {
  23. this.updateBar.Value = obj;
  24. });
  25. work.OnUpdateProgess += new UpdateWork.UpdateProgess((obj) =>
  26. {
  27. this.Invoke(UpdateUIDelegate, (int)obj);
  28. });
  29. }
  30. private void UpdateForm_Load(object sender, EventArgs e)
  31. {
  32. ThreadPool.QueueUserWorkItem((obj) =>
  33. {
  34. try
  35. {
  36. work.Do();
  37. this.DialogResult = DialogResult.OK;
  38. }
  39. catch (Exception EX)
  40. {
  41. MessageBox.Show(EX.Message);
  42. }
  43. });
  44. }
  45. }
  46. }