C# Transaction 事务处理 -依赖事务
在DependentTransaction()方法中,实例化CommittableTransaction类,创建一个根事务,显示事务的信息。接着, tx.DependentClone()方法创建一个依赖的事务。把这个依赖事务传递给TxTask()方法,它定义为新任务的入口。
static void DependentTransaction()
{
var tx = new CommittableTransaction();
Utilities.DisplayTransactionInformation("Root TX created",
tx.TransactionInformation); try
{
Task.Factory.StartNew(TxTask, tx.DependentClone(DependentCloneOption.BlockCommitUntilComplete)); if (Utilities.AbortTx())
{
throw new ApplicationException("transaction abort");
} tx.Commit();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
tx.Rollback();
} Utilities.DisplayTransactionInformation("TX finished",
tx.TransactionInformation); } static void TxTask(object obj)
{
var tx = obj as DependentTransaction;
Utilities.DisplayTransactionInformation("Dependent Transaction",
tx.TransactionInformation); Thread.Sleep(); tx.Complete(); Utilities.DisplayTransactionInformation("Dependent TX Complete",
tx.TransactionInformation);
} public static class Utilities
{
public static void DisplayTransactionInformation(string title, TransactionInformation ti)
{
Contract.Requires<ArgumentNullException>(ti != null); Console.WriteLine(title);
Console.WriteLine("Creation Time: {0:T}", ti.CreationTime);
Console.WriteLine("Status: {0}", ti.Status);
Console.WriteLine("Local ID: {0}", ti.LocalIdentifier);
Console.WriteLine("Distributed ID: {0}", ti.DistributedIdentifier);
Console.WriteLine();
}
}
C# Transaction 事务处理 -依赖事务的更多相关文章
- C# Transaction 事务处理 -环境事务
一.TransactionScope 环境事务 static async Task TransactionScopeAsync() { using (var scope = new Transacti ...
- 14.3.2.1 Transaction Isolation Levels 事务隔离级别
14.3.2 InnoDB Transaction Model InnoDB 事务模型 14.3.2.1 Transaction Isolation Levels 事务隔离级别 14.3.2.2 au ...
- Python Django,事务,transaction.atomic,事务保存点
from django.shortcuts import renderfrom django.http import HttpResponsefrom django.views.generic imp ...
- Compensating Transaction Pattern(事务修正模式)
Undo the work performed by a series of steps, which together define an eventually consistent operati ...
- laravel transaction : laravel 的事务是不支持eloquent的, 要用DB::的方式
数据库事务处理# 你可以使用 transaction 方法,去执行一组数据库事务处理的操作: DB::transaction(function() { DB::table('users')->u ...
- Oracle Database Transaction Isolation Levels 事务隔离级别
Overview of Oracle Database Transaction Isolation Levels Oracle 数据库提供如下事务隔离级别: 已提交读隔离级别 可串行化隔离级别 只读隔 ...
- SET TRANSACTION - 设置当前事务的特性
SYNOPSIS SET TRANSACTION [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ O ...
- START TRANSACTION - 开始一个事务块
SYNOPSIS START TRANSACTION [ ISOLATION LEVEL { READ COMMITTED | SERIALIZABLE } ] [ READ WRITE | READ ...
- SQL Server ->> 高可用与灾难恢复(HADR)技术之 -- Transaction Replication(事务复制)
复制类型: 1)事务型复制:通过复制事务日志到订阅点重做的方式,属于增量型复制: 2)合并型复制:通过触发器和元数据表追踪表数据改变,同样属于增量型复制: 3)快照型复制:通过创建数据库快照,并把快照 ...
随机推荐
- Android 变量取名神器
前言 在工作中,我们还在为起变量名而苦恼吗?今天无意间发现一个专门为变量取名而诞生的神器 codelf. 我们可以直接浏览器访问 http://unbug.github.io/codelf/ 现在我们 ...
- Docker daemon.json 的配置项目合集
这几天看了一点docker相关的东西, 在学习中: 看了下园友的blog 感觉很好 这里 学习一下. https://www.cnblogs.com/pzk7788/p/10180197.html 其 ...
- thinkphp中return $this->fetch的问题
当reture放在foreach循环外面,也就是现在的位置的时候,会报错.如下图.但当return放在foreach语句里面的时候就不会报错,但因为return会结束语句,这也就导致了foreach只 ...
- oracle共享数据库操作
Hello,大家好,这个功能相信新手小白很需要,今天小编因为刚好遇到,所以写出来分享给大家,首先你电脑得有数据库,以及PLSQL工具包,这个相信大家都有了 1.打开NET Manger应用,win10 ...
- 【AtCoder】ARC068
ARC 068 C - X: Yet Another Die Game 显然最多的就是一次6一次5 最后剩下的可能需要多用一次6或者6和5都用上 #include <bits/stdc++.h& ...
- (六)mybatis 全局配置文件讲解
目录 properties (属性) settings 全局参数配置 typeAliases 别名设置 typeHandlers 类型处理器 mapper (映射器) 细节 properties (属 ...
- C++ Primer练习题day2
/* 1.7略 1.8 /* 指出不合法的语句: std::cout<<"/"; std::cout<<"*/ "; std::cout ...
- php源码安装执行configure报错error: off_t undefined; check your library configuration
php安装执行configure报错error: off_t undefined; check your library configuration vim /etc/ld.so.conf 添加如下几 ...
- npm—入门指导
npm npm是什么? NPM(node package manager),通常称为node包管理器.顾名思义,它的主要功能就是管理node包,包括:安装.卸载.更新.查看.搜索.发布等. npm的背 ...
- c#将电脑时间同步到网络时间
最近遇到个项目,需要控制软件使用时间,由于电脑不联网可以修改时间,故需要联网使电脑同步网络时间 网上寻找了很多解决方案,代码如下: //Forproc_Win32.cs//对常用Win32 API函数 ...