Sen System.Transactions.IEnlistmentNotification
arayüzü, this makale uygulamalıdır ve this hazır işlemsel bellek depolama için size
yardımcı olabilir, orada (Software transactional memory), ve STM.NET bunun nihai şeyler değil, ama Microsoft üzerinde çalışıyor!
Bir küçük örnek:
using (TransactionScope tr = new TransactionScope())
{
TsansactionalFileWriter writer = new TsansactionalFileWriter("c:\\myFile.txt");
writer.AppendText("sdfgssdfgsdf");
tr.Complete();
}
* EDTI: Royi İÇİN KATMA G BEKÇİ :) *
using System.Transactions;
namespace Sakher.Transactions
{
public class Royi_s_gReturnerClass
{
private GReturnerEnlistment fileTransactionEnlistment = new GReturnerEnlistment();
public Royi_s_gReturnerClass()
{
Transaction.Current.EnlistVolatile(fileTransactionEnlistment, EnlistmentOptions.None);
}
}
public class GReturnerEnlistment : IEnlistmentNotification
{
public int GOldValue { get; set; }
public GReturnerEnlistment()
{
GOldValue = MyClass.g;
}
public void Commit(Enlistment enlistment)
{
}
public void InDoubt(Enlistment enlistment)
{
}
public void Prepare(PreparingEnlistment preparingEnlistment)
{
preparingEnlistment.Prepared();
}
public void Rollback(Enlistment enlistment)
{
MyClass.g = GOldValue;
}
}
}
Kodunuz olacak kod tüketen
using System.IO;
using System.Text;
using System.Transactions;
namespace Sakher.Transactions
{
public class TsansactionalFileWriter
{
private FileTransactionEnlistment fileTransactionEnlistment = new FileTransactionEnlistment();
public TsansactionalFileWriter(string filePath)
{
fileTransactionEnlistment.FilePath = filePath;
Transaction.Current.EnlistVolatile(fileTransactionEnlistment, EnlistmentOptions.None);
}
public void AppendText(string text)
{
fileTransactionEnlistment.Content.Append(text);
}
public void WriteAllText(string text)
{
fileTransactionEnlistment.Content = new StringBuilder(text);
}
}
public class FileTransactionEnlistment : IEnlistmentNotification
{
public string FilePath { get; set; }
public StringBuilder Content { get; set; }
public FileTransactionEnlistment()
{
Content = new StringBuilder();
}
public void Commit(Enlistment enlistment)
{
File.WriteAllText(FilePath, Content.ToString());
}
public void InDoubt(Enlistment enlistment)
{
}
public void Prepare(PreparingEnlistment preparingEnlistment)
{
//You can create the file here
preparingEnlistment.Prepared();
}
public void Rollback(Enlistment enlistment)
{
//Do ssomething when the transaction is rolled-back (You may delete the file if you have created it!)
}
}
}
:
İşlem yapılabilir hale getirilecek bazı arayüzler vardır, geri dönerken veya yorum yaparken bir şeyler yapmanız gerekir, öyle mi? –
@MSakherSawan I _assume_ var. Bu benim sorum aslında. –