SplashForm.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.ComponentModel;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using System.Windows.Forms;
  6. namespace MediaBrowser.ServerApplication.Splash
  7. {
  8. public partial class SplashForm : Form
  9. {
  10. private readonly TaskScheduler _uiThread;
  11. private readonly Progress<double> _progress;
  12. public SplashForm(Version version, Progress<double> progress)
  13. {
  14. InitializeComponent();
  15. lblVersion.Text = string.Format("Version {0}...", version);
  16. _progress = progress;
  17. progress.ProgressChanged += progress_ProgressChanged;
  18. _uiThread = TaskScheduler.FromCurrentSynchronizationContext();
  19. }
  20. async void progress_ProgressChanged(object sender, double e)
  21. {
  22. await Task.Factory.StartNew(() =>
  23. {
  24. var width = e * 6.48;
  25. panelProgress.Width = Convert.ToInt32(width);
  26. }, CancellationToken.None, TaskCreationOptions.None, _uiThread);
  27. }
  28. protected override void OnClosing(CancelEventArgs e)
  29. {
  30. _progress.ProgressChanged += progress_ProgressChanged;
  31. base.OnClosing(e);
  32. }
  33. }
  34. }