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)快照型复制:通过创建数据库快照,并把快照 ...
随机推荐
- #论文阅读# Universial language model fine-tuing for text classification
论文链接:https://aclweb.org/anthology/P18-1031 对文章内容的总结 文章研究了一些在general corous上pretrain LM,然后把得到的model t ...
- Python 中 参数* 和 **
举个例子就知道了 class test(): def __init__(self, *a, **b): print(a) print(b) print(b.get('test')) tester = ...
- OpsManager管理MongoDB
mydb1 Ops Manager,mongodb,agent mydb2 mongodb,agent mydb3 mongodb,agent NUMA Settings sysctl -w vm.z ...
- k8s认证及serviceAccount、userAccount
1.概述 用kubectl向apiserver发起的命令,采用的是http方式,K8s支持多版本并存. kubectl的认证信息存储在~/.kube/config,所以用curl无法直接获取apis中 ...
- System.Data.EntityException: The underlying provider failed on Open.
场景:IIS默认站点建立程序,使用Windows集成身份验证方式,连接SQLServer数据库也是采用集成身份验证.我报“System.Data.EntityException: The underl ...
- android 自定义控件之NetWorkImageView 处理listview等控件中的图片加载乱序问题
0.调用: BaseAdapter中设置方法 holder.iv.loadImage(url); adapter_xxx.xml 中 控件需要用 xxx.NetWorkImageView 1 NetW ...
- MangoDB CSharp Driver
1.引用MongoDB for C# Driver 从网上下载C#访问MongoDB的驱动,得到两个DLL: MongoDB.Driver.dll MongoDB.Bson.dll 将它们引用到项目中 ...
- 一个jenkins的bug
部署在redhat上docker中的jenkins运行了很久了,最新发现一个站点不是最新的,于是去查看发现git仓库都连不上,我换成外网github的仓库就可以连非得是https吗???? 提示是域名 ...
- Signalr Vue Echarts绘制实时CPU使用率
后端基于Asp.net webapi,前端Vue,前后端分离,该demo仅做演示,实现的细节可以自己优化 Echarts:4.2.1 可参考 官网 Jquery:3.4.1 Signalr:2.4. ...
- 【Android】二、HelloWorld
1. 按照该网址写HelloWorld 例子 http://www.runoob.com/android/android-hello-world-example.html 2.点击 make pr ...