星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System;
  2. using System.Reflection;
  3. using System.Threading;
  4. using System.Windows.Forms;
  5. namespace Common.system
  6. {
  7. /// <summary>
  8. /// 解决闪屏 加载等待
  9. /// 创建人:赵耀
  10. /// 创建时间:2018年11月27日
  11. /// </summary>
  12. public class SplashScreen
  13. {
  14. private static object _obj = new object();
  15. private static Form _SplashForm = null;
  16. private static Thread _SplashThread = null;
  17. private delegate void ChangeFormTextdelegate(string s);
  18. public static void Show(Type splashFormType)
  19. {
  20. if (_SplashThread != null)
  21. {
  22. return;
  23. }
  24. if (splashFormType == null)
  25. {
  26. throw (new Exception());
  27. }
  28. _SplashThread = new Thread(new ThreadStart(delegate ()
  29. {
  30. CreateInstance(splashFormType);
  31. Application.Run(_SplashForm);
  32. }))
  33. {
  34. IsBackground = true
  35. };
  36. _SplashThread.SetApartmentState(ApartmentState.STA);
  37. _SplashThread.Start();
  38. }
  39. public static void ChangeTitle(string status)
  40. {
  41. ChangeFormTextdelegate de = new ChangeFormTextdelegate(ChangeText);
  42. _SplashForm.Invoke(de, status);
  43. }
  44. public static void Close()
  45. {
  46. if (_SplashThread == null || _SplashForm == null)
  47. {
  48. return;
  49. }
  50. try
  51. {
  52. _SplashForm.Invoke(new MethodInvoker(_SplashForm.Close));
  53. }
  54. catch (Exception)
  55. {
  56. }
  57. _SplashThread = null;
  58. _SplashForm = null;
  59. }
  60. private static void ChangeText(string title)
  61. {
  62. _SplashForm.Text = title.ToString();
  63. }
  64. private static void CreateInstance(Type FormType)
  65. {
  66. if (_SplashForm == null)
  67. {
  68. lock (_obj)
  69. {
  70. object obj = FormType.InvokeMember(null,
  71. BindingFlags.DeclaredOnly |
  72. BindingFlags.Public | BindingFlags.NonPublic |
  73. BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
  74. _SplashForm = obj as Form;
  75. _SplashForm.TopMost = true;
  76. _SplashForm.ShowInTaskbar = false;
  77. _SplashForm.BringToFront();
  78. _SplashForm.StartPosition = FormStartPosition.CenterScreen;
  79. if (_SplashForm == null)
  80. {
  81. throw (new Exception());
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }