使用Transactional NTFS的替代方法
鉴于微软有
deprecated Transactional NTFS (TxF):
这意味着我需要一个替代方案: > 我的交易要求相当简单 – 移动两个文件: tx = BeginTransaction(); { MoveFile(testResults,testResultsArchive); //throws if there's a problem MoveFile(cdcResponse,cdcResponseArchive); //throws if there's a problem CommitTransaction(tx); } finally { CloseHandle(tx); } 我已经考虑过将MoveFile转换为CopyFile DeleteFile: CopyFile(testResults,testResultsArchive); //throws if there's a problem CopyFile(cdcResponse,cdcResponseArchive); //throws if there's a problem DeleteFile(testResults); DeleteFile(cdcResponse); 但我希望有一个好的解决方案,而不是一个错误的解决方案.所以我再试一次: CopyFile(testResults,cdcResponseArchive); //throws if there's a problem try { DeleteFile(testResults); } catch (Exception e) { DeleteFile(testResultsArchive); throw e; } try { DeleteFile(cdcResponse); } catch (Exception e) { DeleteFile(cdcResponseArchive); } 除了我希望有一个好的解决方案,而不是一个有缺陷的解决方案. 解决方法
尝试
.NET Transactional File Manager.安全使用它相当简单.页面中的以下示例显示了该方法.它甚至看起来像作者是响应式的,并且能够使用新的有用功能扩展库.
// Wrap a file copy and a database insert in the same transaction TxFileManager fileMgr = new TxFileManager(); using (TransactionScope scope1 = new TransactionScope()) { // Copy a file fileMgr.Copy(srcFileName,destFileName); // Insert a database record dbMgr.ExecuteNonQuery(insertSql); scope1.Complete(); } 如果您对自己的交易经理感兴趣,请务必查看this文章.如果仔细检查上面提到的库,你会发现它是以这种方式实现的. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 在带有WCF的App.config中使用Windows角色身份验证
- windows – Inno设置:使用{pf}在32位/ 64位系统
- CRAN发现R CMD检查–as-cran没有警告
- Windows Server 2012 Standard – Windows应用商
- .net – Windows运行时中的内存管理
- Windows Phone 7 – WP7上的宽瓦通知?
- Windows上的boot2docker – 无法访问暴露的端口
- windows – ShowWindow和ShowWindowAsync有什么区
- 在Windows下调试Android NDK
- 在各种Windows版本上有什么样的SCTP支持?