Message 1 of 19
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'd like you to comment on an issue with is bordering me for some time.
I’ve notice on several posts from Autodesk that Commit is faster than Abort, so why isn't Commit the default.
For instance when this happens i suppose Abort is issued from the Dispose -- Implicitly called by Using.
using (Transaction tr = db.TransactionManager.StartTransaction())
{
if (1==1)
return;
//...
tr.Commit();
}To avoid a lot of if/then blocks one could implement:
using (MyTransaction tr = new MyTransaction(db,true))
{
//...
//if ("YouRealyWantToAbort".Length > 0)
// tr.AutoCommit = false;
if (1 == 1)
return;
//...
tr.Commit();
}
//...
public class MyTransaction : IDisposable
{
private bool disposed = false;
private Database DB { get; set; }
private Transaction TR { get; set; }
public bool AutoCommit { get; set; }
public MyTransaction(Database db, bool autoCommit=true)
{
DB = db;
TR = db.TransactionManager.StartTransaction();
AutoCommit = autoCommit;
//...
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
if (TR!=null && AutoCommit)
TR.Commit();
TR.Dispose();
TR = null;
DB = null;
}
disposed = true;
}
}
//...
- I couldn't find any way to find out if a transaction already is Committed or Aborted.
- Why wouldn't Autodesk added the AutoCommit feature?
Solved! Go to Solution.