2017-09-18 43 views
-2

在我的c#winforms应用程序中,在显示表单的同时我正在加载数据LoadDataAsync方法,但在加载数据之前我想要开始显示启动画面,它是没有发生,有人可以指导我,我做错了什么...或任何想法。如何在执行方法时显示WatiForm异步 - 等待

public partial class DepartmentListDetailView : BaseForm 
    { 
     private DepartmentDataScope _departmentDataScope; 
     private AppConfigDataScope _appConfigDataScope; 
     private DepartmentSearch _departmentSearch; 

     public DepartmentListDetailView() : base() 
     { 
      InitializeComponent(); 
      Init(); 
     } 

     private async void Init() 
     { 
      _departmentDataScope = new DepartmentDataScope(); 
      _appConfigDataScope = new AppConfigDataScope(); 
      _departmentSearch = new DepartmentSearch(); 
      var res = await LoadDataAsync(); 
     }   

     private async Task<bool> LoadDataAsync() 
     { 
      Ssm.ShowWaitForm(); // before loading the data, I want to display the spalsh screen   

      var result = await _departmentDataScope.FetchDataAsync(); 
      BbiSearch.Enabled = true; 
      if (Ssm.IsSplashFormVisible) 
      { 
       this.Invoke((MethodInvoker) Ssm.CloseWaitForm); 
      } 
      return true; 
     } 
    } 

感谢

回答

0

调用像下面的代码异步方法之前表现出来。

 Ssm.ShowWaitForm(); 
     var res = await LoadDataAsync(); 
     if (Ssm.IsSplashFormVisible) 
     { 
      this.Invoke((MethodInvoker) Ssm.CloseWaitForm); 
     }