[Solved] why the async Task always return empty value [closed]


Your problem seems to be that waiting for test().Result causes a dead lock. The reason is that this line

await Task.Delay(1000);

returns the execution flow to the caller, which then calls test().Result to wait for the task to complete. So your main thread is blocking.

The await in the above line tries to resume execution of test when Task.Delay() finishes. But per default it tries to resume this execution on your calling thread. Yes, the thread that is currently blocked because it waits for Result.

One solution maybe to change the line to:

await Task.Delay(1000).ConfigureAwait(false);

This causes await to no longer try to resume on the original thread but any other. This way you avoid the dead lock and your program should continue.

2

solved why the async Task always return empty value [closed]