Await Async:如何在第二个方法启动之前完成一个方法

时间:2016-12-14 18:39:59

标签: async-await

如何进行调用以便在_reportViewerService.ShowReport启动之前完成GetRecords。使用SignalR,setUi更新一个txt字段,该字段显示getRecords中计算结果的部分名称,其余部分应在之后的报告中打印。

(现在发生的是同一时间,然后在我看到实时更新状态之前显示报告)

提前致谢

public async Task ViewReport()
{

  var reportData = await _apiCallExecutor.ExecuteAsync(new GetRecords(queryModel, setUiHooks));
   try
   {
      if (reportData.Count > 0)
      {
        var settings = new ReportSettings();
        settings.ReportPath = "Utilities/SetDeliveryIdByBatchReport";
        settings.ReportTitle = "Set Delivery ID By Batch - Exception Listing";
        settings.DataSources.Add("DeliveryIdExceptionRecords", reportData);
        ReportStatus = "Printing Exception Report...";
        await _reportViewerService.ShowReport(settings);
      }
   }
   finally
   {
     ViewModelState = ViewModelStates.Edit;
   }

   ReportStatus = "Done...";
}

1 个答案:

答案 0 :(得分:0)

您希望使用来自GetRecords的某种“信号”,例如,IObservableTask在数据到达时完成。

class GetRecords
{
  ...
  public Task Done { get; }
  // or: public IObservable<Unit> Done { get; }
}

然后:

var getRecords = new GetRecords(queryModel, setUiHooks);
var reportData = await _apiCallExecutor.ExecuteAsync(getRecords);
await getRecords.Done;
...