title: PetaPoco Transaction in Multithread Env
body: <p>I just test PetaPoco Transaction in a multithread way...</p>
  
  <p>I have a simple test case :</p>
  
  <p>-- Simple value object call it MediaDevice
  -- Insert  a record an update it for 1000 times</p>
  
  <pre><code>void TransactionThread(Object object)
  {
  
  
      Database db = (Database) object;
  
      for(int i= 0; i &lt; 1000;i++)
      {
  
  
          Transaction transaction = db.GetTransaction();
  
          MediaDevice device = new  MediaDevice();
          device.Name = "Name";
          device.Brand = "Brand";
  
          db.Insert(device);
  
          device.Name = "Name_Updated";
          device.Brand = "Brand_Updated";
  
  
          db.Update(device);
  
          transaction.Complete();
  
      }
  
  
      long count = db.ExecuteScalar&lt;long&gt;("SELECT Count(*) FROM MediaDevices");
  
      Console.WriteLine("Number of all records:" + count);
  
  }
  </code></pre>
  
  <p>And I call this in two threads like this:[ Single Database object for both threads]</p>
  
  <pre><code>void TransactionTest()
  {
  
      Database db =  GetDatabase();
  
      Thread tThread1 = ... // thread for  TransactionTest()
  
      Thread tThread2 = ... // thread for  TransactionTest()
  
       tThread1.Start(db); // pass Database to TransactionTest()
       tThread2.Start(db); // pass same Database to TransactionTest()
  
  }
  </code></pre>
  
  <p>I get Null error or sometimes Object disposed error for Database..</p>
  
  <p>But when i  supply two Database instance,</p>
  
  <pre><code>void TransactionTest()
  {
  
      Database db =  GetDatabase();
      Database db2 =  GetDatabase();
  
      Thread tThread1 = ... // thread for  TransactionTest()
  
      Thread tThread2 = ... // thread for  TransactionTest()
  
  
      tThread1.Start(db);  // pass Database instance db to TransactionTest()
      tThread2.Start(db2); // pass Database intance db2 to TransactionTest()
  
  }
  </code></pre>
  
  <p>Everthing is OK...</p>
  
  <p>Well When I check PetaPoco source code at transaction I see that  at transaction.Complete</p>
  
  <pre><code> public virtual void Complete()
          {
              _db.CompleteTransaction();
              _db = null;
          }
  </code></pre>
  
  <p><strong>My question is that  to able to use transaction from multiple threads Do I have to use new copy of Database object? Or what am i doing wrong?</strong></p>
  
  <p>And to make it thread safe do i have to open and close NEW database at every data update-query?</p>