You are developing an application that uses multiple asynchronous tasks to optimize performance. You need to retrieve the result of an asynchronous task. Which code segment should you use?
You are developing an application that uses multiple asynchronous tasks to optimize performance. You need to retrieve the result of an asynchronous task. Which code segment should you use?
C
A should be correct. In C public async Task GetData() wrong
Correct answer is C.
Answer A will cause error because of missing async
protected async void StartTAsk()
{
string result = await GetData();
}
public async Task GetData()
{
string result = “”;
await Task.Run(()=>result=”ok”);
return result;
}
C seems to be correct
C is correct, question says “asynchronous task”