Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

New Post: Request blocked by "await Task.Delay"

$
0
0
I'm having the following simple Web API controller:
    public class MyController : ApiController
    {
        public MyController()
        {
            AsyncTimer();
        }

        [HttpGet]
        public string Get()
        {
            return "asdf";
        }

        private async void AsyncTimer()
        {
            await Task.Delay(10000);
            System.Diagnostics.Debug.WriteLine("Async timer...");
        }
    }
It seems the get request will not return until my AsyncTimer has finished after 10 seconds. But since the return value of AsyncTimer is void, the constructor returns immediately after calling AsyncTimer.

The expected behavior should be letting the AsyncTimer running in parallel with the Get method, any ideas?

Thanks.

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>