Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h3>Edit</h3> <p>Please consider Theo Yaung's <a href="https://stackoverflow.com/questions/5032784/async-ctp-and-finally/5040103#5040103">answer</a>.</p> <h3>Original answer</h3> <p>I'm not familiar with async/await, but after reading this: <a href="http://www.eggheadcafe.com/tutorials/aspnet/e78665f9-b949-4cc7-a024-654eb3bbad6d/visual-studio-async-ctp-overview.aspx" rel="nofollow noreferrer">Visual Studio Async CTP Overview</a></p> <p>and reading your code, I see the <code>await</code> in the <code>Func(int n)</code> function, meaning that from the code <i>after</i> the <code>await</code> keyword till the end of the function will be executed later as a delegate.</p> <p>So <i>my guess</i> (and this is an uneducated guess) is that the <code>Func:Begin</code> and <code>Func:End</code> will possibly execute in different "contexts" (threads?), i.e., asynchronously.</p> <p>Thus, the <code>int u = await Func( i );</code> line in <code>Consumer</code> will continue its execution the moment the code <code>await</code> in <code>Func</code> will be reached. So it is quite possible to have:</p> <pre><code>Consumer: before await #1 Func: Begin #1 Consumer: after await #1 Consumer: before await #2 Func: Begin #2 Consumer: after await #2 Consumer: after the loop Func: End #1 // Can appear at any moment AFTER "after await #1" // but before "After the wait" Func: Finally #1 // will be AFTER "End #1" but before "After the wait" Func: End #2 // Can appear at any moment AFTER "after await #2" // but before "After the wait" Func: Finally #2 // will be AFTER "End #2" but before "After the wait" After the wait // will appear AFTER the end of all the Tasks </code></pre> <p>The <code>Func: End</code> and <code>Func: Finally</code> can appear in whatever position in the logs, the only constraint being that a <code>Func: End #X</code> will appear before its associated <code>Func: Finally #X</code>, and that both should appear before the <code>After the wait</code>.</p> <p>As explained (somewhat abruptly) by Henk Holterman is that the fact you put an <code>await</code> in the <code>Func</code> body means that everything after will be executed <i>sometimes</i> after.</p> <p>There is no workaround as, <code>by design</code> you put a <code>await</code> between the <code>Begin</code> and the <code>End</code> of <code>Func</code>.</p> <p>Just my uneducated 2 eurocents.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload