4 ms·
This might be a little out of scope, but C#/.NET has a few similar constructs. If you do: using(TransactionScope scope = new TransactionScope()){
by Mouse47 9y ago
This might be a little out of scope, but C#/.NET has a few similar constructs. If you do:
using(TransactionScope scope = new TransactionScope()){
//do stuff
}
Any connection created while that block is active will 'enlist' in the transaction associated with that scope. This works (I think...can't find it now) by using something called 'CallContext', which is more or less a static key-value store that's persisted up and down the call stack (including through async continuations, not sure how that works).
If the 'CallContext' is static, doesn't that mean it's global and shared between threads? Well...in C# that's not necessarily true since the thread is accessible via a static property and it's possible to store data against the thread (which is exactly what 'CallContext' does, plus some magic that moves the data during async continuations in case the execution thread changes)