I'm trying to integrate async
/await
into our service bus.
I implemented a SingleThreadSynchronizationContext
based on this example http://blogs.msdn.com/b/pfxteam/archive/2012/01/20/10259049.aspx.
And it works fine, except for one thing: TransactionScope
. I await for stuff inside the TransactionScope
and it break the TransactionScope
.
TransactionScope
doesn't seems to play nice with the async
/await
, certainly because it store things in the thread using ThreadStaticAttribute
. I get this exception :
"TransactionScope nested incorrectly.".
I tried to save TransactionScope
data before queuing the task and restore it before running it but it doesn't seems to change a thing. And TransactionScope
code is a mess, so it's really hard to understand what's going on there.
Is there a way to make it work ? Is there some alternative to TransactionScope
?
SingleThreadSynchronizationContext
for each top-levelTransactionScope
. – Stephen Cleary Nov 25 '12 at 14:24