我使用.Net 8环境创建了一个控制台应用程序,Program.cs中有以下代码:
TransactionManager.ImplicitDistributedTransactions = true;
var transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
transactionOptions.Timeout = TimeSpan.FromSeconds(3600);
using (IDbConnection connection1 = new SqlConnection(infocitiConnectionString))
using (IDbConnection connection2 = new SqlConnection(storageConnectionString))
{
TransactionScope ts = null;
try
{
ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions);
{
connection1.Open();
//connection1.Execute(sql: sqlDelete);
connection1.Close();
connection2.Open();
//connection2.Execute(sql: sqlInsert);
connection2.Close();
ts.Complete();
}
}
finally
{
ts?.Dispose();
}
}
不幸的是,我在代码行上陷入了僵局:
ts?.Dispose();
我搜索了互联网和net 8源代码但没有找到明确的内容
如果我注释掉
ts.Complete();
代码,死锁就会消失。
我将 Microsoft.Data.SqlClient 包从版本 2.1.5 更新到最后一个实际版本(5.1.2),死锁消失了