2

Given that async / await doesn't inherently create a thread and the awaited I/O operation is completed outside of a thread's context, how is one supposed to determine what operations are currently being executed?

To experiment, I put together a small test app which would fire off 1 long-running IO operation and awaited it. I ran the test program and during the the long running IO operation, created a dump file and inspected the threads using WinDbg. Nowhere within the thread stacks was it clear (to me at least) of that awaited call. I didn't see any of my .Net code, I didn't see any class references of the library I was calling (Amazon in this case).

I tried the same thing, but fired off 3 long-running IO operations all at the same time and awaited them. I created another dump file. My threads and stack traces look nearly identical.

How are situations like this debugged? How would I determine what is "running" right now when my app basically appears to look like its idle in terms of its thread's call stacks? The closest solution I've come up with is to inspect the heap and look for objects I know would be allocated during that awaited operations and see how many exist. (i.e. 3 WebRequest objects, etc.)

Surly there is a better method to this!

Ryan Griffith
  • 1,591
  • 17
  • 41
  • Can't you just add a breakpoint in Visual Studio? Furthermore, what problem are you trying to solve by seeing what is executing? – Dan Wilson Jul 31 '18 at 20:13
  • 1
    [Eduasync](https://codeblog.jonskeet.uk/category/eduasync/). -- [Top 5 ways to debug async/await and multi-threaded code in Visual Studio](https://blog.oz-code.com/debugging-multi-threaded-code-using-visual-studio-ozcode/). -- [Using the Debugger with Async Methods](https://msdn.microsoft.com/en-us/library/jj155813.aspx?f=255&MSPPError=-2147217396). – Jimi Jul 31 '18 at 20:16
  • 1
    What does your code look like? What are you doing to be "long-running"? Maybe your "long-running" code is not running at all. If it's a long-running I/O operation, you don't have any code running; you're simply awaiting its result - that's kinda-sorta the point of "await" – Flydog57 Jul 31 '18 at 20:29
  • @Flydog57, I completely understand. That was the point I was trying to make in my first sentence. I realize there isn't anything being "executed", at least not within the code I wrote, but I would like to know where the execution of my code stopped and the IO took-over. In other words, I would like to know where I am in my program (I think that's a reasonable expectation from the developer's perspective). – Ryan Griffith Jul 31 '18 at 20:35
  • @RyanGriffith May be filtering dump will give you some usefult info: https://stackoverflow.com/questions/44311546/how-to-list-running-tasks-in-net-memory-dump – Dipen Shah Jul 31 '18 at 20:54

0 Answers0