如何调用异步方法C# [英] How to call async methods C#
本文介绍了如何调用异步方法C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i在C#中有以下方法。
Hi,
i have following method in C#.
public async Task<ObservableCollection<Vehicle>> GetDataAsync(string vehicleId)
我尝试过:
i我使用下面的代码调用此方法。
What I have tried:
i am calling this method using below code.
var data = GetDataAsync("123");
i我收到以下错误消息。
Id = 9,Status = WaitingForActivation,Method ={null},Result ={Not yet computed}
任何人都可以帮助调用方法。
谢谢..
i am getting the following error message.
Id = 9, Status = WaitingForActivation, Method = "{null}", Result = "{Not yet computed}
can any one help how to call methods.
Thanks..
推荐答案
尝试明确声明
任务< observablecollection> task = GetDataAsync(123);
var result =等待任务;
但似乎错误的是调用方法也调用了另一个异步,所以如果使用等待更好
plz check al所以
使用Async和Await进行异步编程(C#和Visual Basic) [ ^ ]
也在方法名称之前放置异步,从而调用此方法。
also put async before method name from where u'r calling this method.
>
这篇关于如何调用异步方法C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文