ThreadStatic in async/await - LogicalCallContext doesn't flow outside of async method?
<p>I'm trying to implement a reentrant <code>Monitor</code>-like primitive for async/await.</p>

<pre><code>    public async Task&lt;DisposableAction&gt; LockAsync()
    {
        // await current executing task;
        // ...
        if (_reentrant)
        {
            var list = CallContext.LogicalGetData(CallContextListName) as HashSet&lt;AsyncLock&gt;;
            if (list != null &amp;&amp; list.Contains(this)) return new DisposableAction();

            list = list ?? new HashSet&lt;AsyncLock&gt;();
            list.Add(this);
            CallContext.LogicalSetData(CallContextListName, list);
        }
        // acquire a "lock" and return IDisposable that removes from list
        // ...
    }
</code></pre>

<p>The calling code looks like:</p>

<pre><code> using (await _lock.LockAsync())
 {
     // ...
     return await PossibleRecursiveMethod();
 }
</code></pre>

<p>I'm debugging this and it looks like the <em>CallContextListName</em> object is present in <code>CallContext</code> inside <code>LockAsync</code> method but disappears when execution reaches the first statement inside <code>using</code> block.</p>

<p>I'm doing this on .NET 4.5.2 so <code>LogicalCallContext</code> should work I guess. So what's wrong? How it should be implemented?</p>