DKFormBase.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:DKFormBase.cs
  5. * 2.功能描述:扩展的窗口:单实例、异步共通处理等。
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2015/03/27 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Windows.Forms;
  12. using Dongke.IBOSS.PRD.Basics.BaseControls;
  13. using Dongke.IBOSS.PRD.Basics.BaseResources;
  14. using Dongke.IBOSS.PRD.WCF.DataModels;
  15. namespace Dongke.IBOSS.PRD.Client.Controls
  16. {
  17. /// <summary>
  18. /// 扩展的窗口
  19. /// </summary>
  20. public partial class DKFormBase : FormBase
  21. {
  22. #region 构造函数
  23. /// <summary>
  24. /// 构造函数
  25. /// </summary>
  26. protected DKFormBase()
  27. {
  28. InitializeComponent();
  29. }
  30. #endregion 构造函数
  31. #region 程序异步处理
  32. /// <summary>
  33. /// 窗体的异步处理
  34. /// </summary>
  35. /// <param name="method">异步方法</param>
  36. /// <returns></returns>
  37. public T DoAsync<T>(DKAsyncMethod<T> method)
  38. {
  39. T result = default(T);
  40. try
  41. {
  42. this.StartProgress();
  43. IAsyncResult asyncResult = method.BeginInvoke(null, null);
  44. while (!asyncResult.IsCompleted)
  45. {
  46. Application.DoEvents();
  47. System.Threading.Thread.Sleep(1);
  48. }
  49. result = method.EndInvoke(asyncResult);
  50. }
  51. catch (Exception ex)
  52. {
  53. throw ex;
  54. }
  55. finally
  56. {
  57. this.EndProgress();
  58. if (result is ServiceResultEntity)
  59. {
  60. ServiceResultManager.Invoke(this, result as ServiceResultEntity);
  61. }
  62. }
  63. return result;
  64. }
  65. #endregion
  66. }
  67. }