Confusion regarding threads and if asynchronous methods are truly asynchronous in C#

Viewed 6357

I was reading up on async/await and when Task.Yield might be useful and came across this post. I had a question regarding the below from that post:

When you use async/await, there is no guarantee that the method you call when you do await FooAsync() will actually run asynchronously. The internal implementation is free to return using a completely synchronous path.

This is a little unclear to me probably because the definition of asynchronous in my head is not lining up.

In my mind, since I do mainly UI dev, async code is code that does not run on the UI thread, but on some other thread. I guess in the text I quoted, a method is not truly async if it blocks on any thread (even if it's a thread pool thread for example).

Question:

If I have a long running task that is CPU bound (let's say it is doing a lot of hard math), then running that task asynchronously must be blocking some thread right? Something has to actually do the math. If I await it then some thread is getting blocked.

What is an example of a truly asynchronous method and how would they actually work? Are those limited to I/O operations which take advantage of some hardware capabilities so no thread is ever blocked?

7 Answers
Related