序列化交易似乎没有中止?

时间:2013-04-02 18:11:44

标签: c# transactions transactionscope

我正在尝试序列化交易,例如:

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;
}

但是在WriteLines这两个上,由于某种原因,该事务被报告为活动状态。如果我在没有序列化的情况下做同样的事情,那么行为应该是(它会中止),但是当我将它序列化时,它会突然停止正常运行。我做错了什么?

0 个答案:

没有答案