Reputation: 277
Hej, I have a method:
public static async Task<myClassl> GetData()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http:sasa.com");
HttpResponseMessage response = await client.GetAsync("api/GetData");
myClassl data = await response.Content.ReadAsAsync<myClassl>();
return data ;
}
And when I write
myClassl t = await DataGetter.GetData();
I have: The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
Upvotes: 0
Views: 387
Reputation: 564323
You need to flag your method async
where you write:
// Add async to your calling method
private async Task SomeOtherMethod()
{
myClassl t = await DataGetter.GetData();
Any method that uses await
internally must be an async
method itself.
Upvotes: 3