Makubex
Makubex

Reputation: 1114

TransactionScope and DependantTransaction

Can I get an example usage that is not related to either DB or File-IO?

I've read about IEnlistmentNotification and Transactions and was wondering if I can use Transactional behavior for my custom classes (like my own resource manager) which is in memory only?

Scenario I was wondering - Let's say I have some data structure in memory which has some 5 properties (thread safe). I launch 5 threads to update one property each (lets say its computationally intensive). Now 4 may succeed and 5th may fail in which case I want to roll-back my data structure to its original state. Can I implement DependantTransaction for this case?

PS: I know I can manually save a cloned copy, revert it back in catch block, etc.

Upvotes: 1

Views: 265

Answers (2)

Makubex
Makubex

Reputation: 1114

Found these if any one else is interested -

Another SO question

STM in C#

STM.NET Library

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1062770

There have been some 3rd-party implementations of transaction-scope providers for in-memory objects; however, generally speaking they're a bit flakey and not really worth the pain - especially since you are using threading. Frankly, I strongly suggest you look more at regular memento patterns, or immutable data structures that don't need rolling back (i.e. you just discard the separate, mutated copy).

Yes it can probably be done, but unless writing a transaction-scope provider is the purpose of your project, I would recommend you focus on delivering application logic first. Just sayin'

Upvotes: 1

Related Questions