Chapter 25

Transactions

WHAT’S IN THIS CHAPTER?

  • Transaction phases and ACID properties
  • Traditional transactions
  • Committable transactions
  • Transaction promotions
  • Dependent transactions
  • Ambient transactions
  • Transaction isolation levels
  • Custom resource managers
  • Transactions with Windows 8 and Windows Server 2012

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code downloads for this chapter are found at http://www.wrox.com/remtitle.cgi?isbn=1118314425 on the Download Code tab. The code for this chapter is divided into the following major examples:

  • Transaction Samples
  • Multithreading Ambient Transactions
  • Custom Resource
  • Windows 8 Transactions

INTRODUCTION

All or nothing — this is the main characteristic of a transaction. When writing a few records, either all are written, or everything will be undone. If there is even one failure when writing one record, all the other things that are done within the transaction will be rolled back.

Transactions are commonly used with databases, but with classes from the namespace System.Transactions, you can also perform transactions on volatile or in-memory-based objects such as a list of objects. With a list that supports transactions, if an object is added or removed and the transaction fails, the list action is automatically undone. Writing to a memory-based list can be done in the same transaction as writing to a database.

Since Windows Vista, the file system and registry also have transactional support. Writing a file and making changes ...

Get Professional C# 2012 and .NET 4.5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.