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?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
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?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Same as below:
https://www.aiotestking.com/microsoft/which-code-segment-should-you-use-1082/
If you answer C, compiler rise a warning, but aslso suggest to remove async Task from GetData.
For me the right answer (that compiles as well) is A
should be C (https://msdn.microsoft.com/en-us/magazine/jj991977.aspx)
Async all the way Don’t mix blocking and async code
class AwnserC
{
protected async void StartTask()
{
string restult = await GetData();
}
public async Task GetData()
{
await Task.Delay(1000);
return “test”;
}
}