![](/img/trans.png)
[英]Async non-polling disposal mechanism to wait until all method calls are finished in .NET 5 C#
[英]Wait for Async method calls in c#
我有以下WCF服務
public bool RefreshDB()
{
if (twcPMRefresh())
status = true;
if (twcCommonRefresh())
status = true;
}
twcPMRefresh()和twcCommonRefresh()方法內部的邏輯是異步的,因此我想等到“ twcPMRefresh”執行完成后再調用twcCommonRefresh。 兩種方法都比較少,如下所示。
public bool twcPMRefresh()
{
tweets=await
(from tweet in GetTwitterContext(localProxyIP,fCode).Status
where tweet.Type == StatusType.User &&
select tweet)
.ToListAsync();
--use 'tweets' list to insert in database
}
可以請協助。 謝謝!!
您可以使用await async
方法:
假設您的twcPMRefresh()
和twcCommonRefresh()
方法都是ASYNC,則可以這樣編寫:
public async bool RefreshDB()
{
if (await twcPMRefresh())
status = true;
if (await twcCommonRefresh())
status = true;
}
您的方法RefreshDB()
現在可以通過以下兩種方式調用:
bool result = RefreshDB().Result()
bool result = await RefreshDB(); //Needs an async Method or a task to be used.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.