C# 序列化事务不';你似乎没有放弃?
我正在试验序列化事务,例如:C# 序列化事务不';你似乎没有放弃?,c#,transactions,transactionscope,C#,Transactions,Transactionscope,我正在试验序列化事务,例如: public static void Main() { MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.Fro
public static void Main()
{
MemoryStream stream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromMinutes(1)))
{
formatter.Serialize(stream, Transaction.Current);
stream.Seek(0, SeekOrigin.Begin);
MemoryStream result = Second(stream);
Transaction transaction = (Transaction)formatter.Deserialize(result);
Console.WriteLine(transaction.TransactionInformation.Status);
}
Console.ReadLine();
}
public static MemoryStream Second(MemoryStream stream)
{
BinaryFormatter formatter = new BinaryFormatter();
Transaction transaction = (Transaction)formatter.Deserialize(stream);
using (TransactionScope scope2 = new TransactionScope(transaction))
{
}
Console.WriteLine(transaction.TransactionInformation.Status);
MemoryStream newStream = new MemoryStream();
formatter.Serialize(newStream, transaction);
newStream.Seek(0, SeekOrigin.Begin);
return newStream;
}
但在这两个写行上
,由于某种原因,事务被报告为处于活动状态。如果我在没有序列化的情况下做同样的事情,行为就是它应该做的(它会中止),但是当我序列化它时,它会突然停止正常的行为。我做错了什么