public static void EndSharedTransaction(object source, bool rollback = false) { Monitor.Enter(SharedConnection); try { if (SharedConnection.State != System.Data.ConnectionState.Closed && source == initialSource) { if (mustRollback || rollback) { SharedTransaction.Rollback(); } else { SharedTransaction.Commit(); } SharedConnection.Close(); } else if (source != initialSource) { mustRollback = rollback; } } finally { Monitor.Exit(SharedConnection); } }