久久久久久久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 的原因)
主站蜘蛛池模板: 日韩一区二区免费视频 | h在线免费观看 | 免费视频一区二区三区在线观看 | 久久久久久国产一区二区三区 | 天天躁日日躁xxxxaaaa | 国产一区二区三区免费观看视频 | 精品国产乱码久久久久久牛牛 | 国产高清在线 | 亚洲a一区二区 | 精品视频在线观看 | 日韩一区二区视频 | 国产2区| 福利片在线 | 国产免费观看视频 | 日韩一级精品视频在线观看 | 少妇一级淫片免费放播放 | 日韩区| 国产成人高清成人av片在线看 | 亚洲精品一区二区在线 | 国产免费又黄又爽又刺激蜜月al | 欧美黑人又粗大 | 欧美成ee人免费视频 | 国产精品一区二 | 一级黄色片一级黄色片 | av在线播放网址 | 成人av网页| 欧美一区二区成人 | 欧美日韩亚洲国产 | 91色视频在线观看 | 黄色av大片 | 免费v片| 日本超碰 | 精品国产欧美 | 色av一区二区三区 | 精品久久香蕉国产线看观看亚洲 | 午夜三级视频 | 一区二区三区在线播放 | 嫩呦国产一区二区三区av | 伊人一区 | www.精品国产 | 国产第一页在线播放 |