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

如何在可取消的 async/await 中處理 TransactionScope?

How to dispose TransactionScope in cancelable async/await?(如何在可取消的 async/await 中處理 TransactionScope?)
本文介紹了如何在可取消的 async/await 中處理 TransactionScope?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用新的 async/await 功能來異步處理數據庫.由于某些請求可能很長,我希望能夠取消它們.我遇到的問題是 TransactionScope 顯然具有線程關聯性,而且似乎在取消任務時,它的 Dispose() 在錯誤的線程上運行.

I'm trying to use the new async/await feature to asynchronously work with a DB. As some of the requests can be lengthy, I want to be able to cancel them. The issue I'm running into is that TransactionScope apparently has a thread affinity, and it seems that when canceling the task, its Dispose() gets ran on a wrong thread.

具體來說,當調用 .TestTx() 時,我在 task.Wait () 上得到以下 AggregateException 包含 InvalidOperationException代碼>:

Specifically, when calling .TestTx() I get the following AggregateException containing InvalidOperationException on task.Wait ():

"A TransactionScope must be disposed on the same thread that it was created."

代碼如下:

public void TestTx () {
    var cancellation = new CancellationTokenSource ();
    var task = TestTxAsync ( cancellation.Token );
    cancellation.Cancel ();
    task.Wait ();
}

private async Task TestTxAsync ( CancellationToken cancellationToken ) {
    using ( var scope = new TransactionScope () ) {
        using ( var connection = new SqlConnection ( m_ConnectionString ) ) {
            await connection.OpenAsync ( cancellationToken );
            //using ( var command = new SqlCommand ( ... , connection ) ) {
            //  await command.ExecuteReaderAsync ();
            //  ...
            /
                
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發問題)
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 的原因)
主站蜘蛛池模板: 亚洲精品91| 黄色一级大片在线免费看国产一 | 国产精品视频一区二区三区 | 亚洲一区国产 | 一级片国产| 福利网站在线观看 | 黄色在线免费观看视频 | 国产精品手机在线 | 日本一区二区不卡视频 | 日韩三级中文字幕 | 91久久精品日日躁夜夜躁欧美 | 8x8ⅹ国产精品一区二区 | 日韩精品在线看 | 日本特级淫片 | 久久久久国产一区二区三区 | 国产亚洲欧美在线 | 亚洲伊人av | 日韩午夜精品 | 亚洲免费久久 | 国产精品成人一区二区三区 | 亚洲综合在线视频 | 亚洲精品自拍视频 | 免费看大片a | 日韩一区二区三区视频 | 韩日一区二区 | 成人三级视频在线观看 | 国产欧美日韩综合 | 日韩av在线不卡 | 九九九视频 | 亚洲精品久久 | 狠狠干综合| 美女一级片| 成人a毛片 | 国产一区免费在线观看 | 日韩网站在线观看 | 中文字幕二区 | 一级毛片免费播放 | 性生活视频网站 | 深夜免费福利 | 日韩一区二区免费视频 | 99re国产精品 |