2017-04-06 56 views
1
private async Task<List<T>> Ex_Event(string telNo) 
{ 
    SearchConditionData scd = new SearchConditionData { tel=telNo };    
    List<T> list = await RequestAsync<SearchConditionData, List<T>>(scd, Service.GetIncident); 

    historyList = (...).Take(30).ToList();   

    return historyList; 
} 

我做了一个方法,返回列表<>。如何计算任务中的列表?

但我修改它async,然后我不能使用List.Count。

这里是我的代码的一部分。

public delegate Task<List<IncidentListData>> HistoryEvent(string telNo); 
public event HistoryEvent myHistoryEvent; 

返回类型是任务<>。我想检查任务中的计数列表。

if (myHistoryEvent(Tel).Count > 0) 

但它不起作用。我不能使用异步,因为我在Interface中调用myHistoryEvent()public string this[string name](IDataErrorInfo)

如何检查任务中List的计数?

+2

有很多关于此的教程,您应该尝试首先了解基本知识。 – Robert

回答

0

你可以检查你的任务结果。

myHistoryEvent(Tel).Result.Count > 0 

内部结果类型列表任务> .Result。

+0

哇真的很简单!谢谢 :) – parfum