久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

TransactionScope 和多線程

TransactionScope and multi-threading(TransactionScope 和多線程)
本文介紹了TransactionScope 和多線程的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想知道在處理多線程時如何以正確的方式使用 TransactionScope 類?

I was wondering how you would use the TransactionScope class in the correct way when you are dealing with multithreading?

我們在主線程中創建了一個新的作用域,然后我們產生了幾個工作線程,我們希望這些線程參與到主作用域中,例如,如果作用域從未完成,則在每個工作線程上調用回滾.

We create a new scope in our main thread and then we spawn off a couple of worker threads and we want these to participate in the main scope, so that for example the rollback is called on each worker if the scope is never completed.

我在內部使用 ThreadStaticAttribute 閱讀了有關 TransactionScope 的內容,這使得上述操作變得不可能/非常困難 - 有人可以驗證任何一種方式嗎?如果我們以同步方式運行代碼,則回滾工作,即內部事務能夠參與主事務,但如果我們切換到線程執行則不行.

I read something about TransactionScope using the ThreadStaticAttribute internally which made the above impossible / very difficult - could someone verify either way? If we run our code in a synchronized fashion then the rollbacks work, i.e the inner transactions are able to participate in the main transaction, but not if we switch over to a threaded execution.

推薦答案

參見 MSDN:

您還應該使用 TransactionScope 和DependentTransaction 類需要使用的應用程序同一筆交易跨多個函數調用或多線程電話.

You should also use the TransactionScope and DependentTransaction class for applications that require the use of the same transaction across multiple function calls or multiple thread calls.

所以也許看看 DependentTransaction - 特別是,有一個工作線程示例,這里.

So maybe look into DependentTransaction - in particular, there is a worker thread example, here.

這篇關于TransactionScope 和多線程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

SQL Server 2005 Transaction Level and Stored Procedures(SQL Server 2005 事務級和存儲過程)
Yield return from a try/catch block(try/catch 塊的收益回報)
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務的 SqlCommand 時,我應該調用 Parameters.Clear 嗎?)
Does SqlTransaction need to have Dispose called?(SqlTransaction 是否需要調用 Dispose?)
Reason for System.Transactions.TransactionInDoubtException(System.Transactions.TransactionInDoubtException 的原因)
How do I use TransactionScope with MySql and Entity Framework? (getting Multiple simultaneous connections...are not currently supported error)(如何將 TransactionScope 與 MySql 和實體框架一起使用?(獲取多個同時連接...目前不
主站蜘蛛池模板: 久久国产一区二区 | 中文成人在线 | 久久毛片 | 给我免费的视频在线观看 | 亚洲一区久久 | 欧美簧片 | 一区二区三区国产好 | 国产精品国产精品国产专区不卡 | 啪啪免费网站 | 久久99国产精品 | 亚洲电影专区 | h视频免费观看 | 免费午夜视频在线观看 | 黄视频免费 | 黄色在线免费观看视频 | 成人在线精品 | 一区精品国产欧美在线 | 久久精品视频网站 | 久久国产一区 | 性一交一乱一伦视频免费观看 | 黄色一级片aaa | 国产精品自产拍在线观看蜜 | 成人午夜激情 | 国产精品国产亚洲精品看不卡15 | 老司机深夜福利网站 | 欧美精品一区二区三区四区五区 | 一区二区三区欧美在线 | 精品视频在线播放 | 99视频免费看 | 国产精品免费一区二区三区四区 | 天天曰夜夜| 91视频国产精品 | 亚洲精品一区二三区不卡 | 九九免费在线视频 | av永久 | 亚洲色在线视频 | 免费在线播放黄色 | 亚洲二区视频 | 欧美v日韩v | 欧美一区二区三区在线观看 | 超碰人人91 |