撰寫異動式應用程式Writing a Transactional Application

身為交易式應用程式設計人員,您可以利用 System.Transactions 命名空間所提供的兩個程式撰寫模型 (Programming Model) 來建立交易。As a transactional application programmer, you can take advantage of the two programming models provided by the System.Transactions namespace to create a transaction. 您可以使用Transaction類別來利用明確的程式設計模型, 或透過TransactionScope使用類別, 將交易由基礎結構自動管理的隱含程式設計模型運用。You can utilize the explicit programming model by using the Transaction class, or the implicit programming model in which transactions are automatically managed by the infrastructure, by using the TransactionScope class. 我們建議您將隱含的交易模型用於開發。We recommend that you use the implicit transaction model for development. 您可以在使用交易範圍來執行隱含交易主題中找到有關如何使用交易範圍的詳細資訊。You can find more information on how to use a transaction scope in the Implementing an Implicit Transaction using Transaction Scope topic.

兩種模型都支援在程式到達一致的狀態時認可交易。Both models support committing a transaction when the program reaches a consistent state. 一旦成功認可,就會永久地認可交易。If the commit succeeds, the transaction is durably committed. 如果認可失敗,就會中止交易。If the commit fails, the transaction aborts. 如果應用程式無法成功完成交易,就會嘗試中止並復原交易影響。If the application program cannot successfully complete the transaction, it attempts to abort and undo the transaction's effects.

本節內容In This Section

建立交易Creating a Transaction

System.Transactions 命名空間會提供兩種用來建立交易的模型。The System.Transactions namespace provides two models for creating a transaction. 下列主題涵蓋這些模式。These models are covered in the following topics.

使用異動範圍實作隱含異動Implementing an Implicit Transaction using Transaction Scope

說明 System.Transactions 命名空間如何透過 TransactionScope 類別來支援建立隱含的交易。Describes how the System.Transactions namespace supports creating implicit transactions using the TransactionScope class.

使用 CommittableTransaction 實作明確異動Implementing an Explicit Transaction using CommittableTransaction

說明 System.Transactions 命名空間如何透過 CommittableTransaction 類別來支援建立明確的交易。Describes how the System.Transactions namespace supports creating explicit transactions using the CommittableTransaction class.

擴大交易管理Escalating Transaction Management

當交易需要存取位於另一個應用程式定義域的資源時,或是當您想要登記到另一個永久性的資源管理員時,交易會自動擴大為受到 MSDTC 管理。When a transaction needs to access a resource in another application domain, or if you want to enlist in another durable resource manager, the transaction is automatically escalated to be managed by the MSDTC. 交易管理擴大主題中會涵蓋交易擴大。Transaction escalation is covered in the Transaction Management Escalation topic.

並行Concurrency

使用DependentTransaction 管理並行的主題會示範如何使用DependentTransaction類別, 在非同步工作之間達成平行存取。The topic Managing Concurrency with DependentTransaction demonstrates how concurrency can be achieved between asynchronous tasks by using the DependentTransaction class.

COM+ InteropCOM+ Interop

與 Enterprise Services 和 COM + 交易的互通性主題會說明如何讓您的分散式交易與 com + 交易進行互動。The topic Interoperability with Enterprise Services and COM+ Transactions illustrates how you can make your distributed transactions interact with COM+ transactions.

診斷Diagnostics

診斷追蹤會描述如何使用System.Transactions基礎結構所產生的追蹤程式碼, 來疑難排解應用程式中的錯誤。Diagnostic Traces describes how you can use the trace codes that are generated by the System.Transactions infrastructure to troubleshoot errors in your applications.

使用 ASP.NETWorking within ASP.NET

ASP.NET 主題中的 Using system.string 一節會說明如何在 ASP.NET 應用System.Transactions程式內成功使用。The Using System.Transactions in ASP.NET topic describes how you can successfully use System.Transactions inside an ASP.NET application.