2017-09-18 45 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); 
     }