Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Dispose()

void System.Transactions.TransactionScope.Dispose ( )
inline

Implements System.IDisposable.

Definition at line 346 of file TransactionScope.cs.

347 {
348 bool flag = false;
349 TransactionsEtwProvider log = TransactionsEtwProvider.Log;
350 if (log.IsEnabled())
351 {
352 log.MethodEnter(TraceSourceType.TraceSourceBase, this, "Dispose");
353 }
354 if (_disposed)
355 {
356 if (log.IsEnabled())
357 {
358 log.MethodExit(TraceSourceType.TraceSourceBase, this, "Dispose");
359 }
360 return;
361 }
363 {
364 if (log.IsEnabled())
365 {
366 log.InvalidOperation("TransactionScope", "InvalidScopeThread");
367 }
369 }
370 Exception ex = null;
371 try
372 {
373 _disposed = true;
375 Transaction contextTransaction = null;
376 Transaction transaction = Transaction.FastGetTransaction(currentScope, _threadContextData, out contextTransaction);
377 if (!Equals(currentScope))
378 {
379 if (currentScope == null)
380 {
381 Transaction transaction2 = _committableTransaction;
382 if (transaction2 == null)
383 {
384 transaction2 = _dependentTransaction;
385 }
386 transaction2.Rollback();
387 flag = true;
388 throw TransactionException.CreateInvalidOperationException(TraceSourceType.TraceSourceBase, System.SR.TransactionScopeInvalidNesting, null, transaction2.DistributedTxId);
389 }
390 if (currentScope._interopOption == EnterpriseServicesInteropOption.None && ((null != currentScope._expectedCurrent && !currentScope._expectedCurrent.Equals(transaction)) || (null != transaction && null == currentScope._expectedCurrent)))
391 {
392 TransactionTraceIdentifier currenttransactionID = ((!(null == transaction)) ? transaction.TransactionTraceId : TransactionTraceIdentifier.Empty);
393 TransactionTraceIdentifier newtransactionID = ((!(null == _expectedCurrent)) ? _expectedCurrent.TransactionTraceId : TransactionTraceIdentifier.Empty);
394 if (log.IsEnabled())
395 {
396 log.TransactionScopeCurrentChanged(currenttransactionID, newtransactionID);
397 }
398 ex = TransactionException.CreateInvalidOperationException(TraceSourceType.TraceSourceBase, System.SR.TransactionScopeIncorrectCurrent, null, (transaction == null) ? Guid.Empty : transaction.DistributedTxId);
399 if (null != transaction)
400 {
401 try
402 {
403 transaction.Rollback();
404 }
406 {
407 }
408 catch (ObjectDisposedException)
409 {
410 }
411 }
412 }
413 while (!Equals(currentScope))
414 {
415 if (ex == null)
416 {
417 ex = TransactionException.CreateInvalidOperationException(TraceSourceType.TraceSourceBase, System.SR.TransactionScopeInvalidNesting, null, (transaction == null) ? Guid.Empty : transaction.DistributedTxId);
418 }
419 if (null == currentScope._expectedCurrent)
420 {
421 if (log.IsEnabled())
422 {
423 log.TransactionScopeNestedIncorrectly(TransactionTraceIdentifier.Empty);
424 }
425 }
426 else if (log.IsEnabled())
427 {
428 log.TransactionScopeNestedIncorrectly(currentScope._expectedCurrent.TransactionTraceId);
429 }
430 currentScope._complete = false;
431 try
432 {
433 currentScope.InternalDispose();
434 }
436 {
437 }
438 currentScope = _threadContextData.CurrentScope;
439 _complete = false;
440 }
441 }
442 else if (_interopOption == EnterpriseServicesInteropOption.None && ((null != _expectedCurrent && !_expectedCurrent.Equals(transaction)) || (null != transaction && null == _expectedCurrent)))
443 {
444 TransactionTraceIdentifier currenttransactionID2 = ((!(null == transaction)) ? transaction.TransactionTraceId : TransactionTraceIdentifier.Empty);
445 TransactionTraceIdentifier newtransactionID2 = ((!(null == _expectedCurrent)) ? _expectedCurrent.TransactionTraceId : TransactionTraceIdentifier.Empty);
446 if (log.IsEnabled())
447 {
448 log.TransactionScopeCurrentChanged(currenttransactionID2, newtransactionID2);
449 }
450 if (ex == null)
451 {
452 ex = TransactionException.CreateInvalidOperationException(TraceSourceType.TraceSourceBase, System.SR.TransactionScopeIncorrectCurrent, null, (transaction == null) ? Guid.Empty : transaction.DistributedTxId);
453 }
454 if (null != transaction)
455 {
456 try
457 {
458 transaction.Rollback();
459 }
461 {
462 }
463 catch (ObjectDisposedException)
464 {
465 }
466 }
467 _complete = false;
468 }
469 flag = true;
470 }
471 finally
472 {
473 if (!flag)
474 {
475 PopScope();
476 }
477 }
479 if (ex != null)
480 {
481 throw ex;
482 }
483 if (log.IsEnabled())
484 {
485 log.MethodExit(TraceSourceType.TraceSourceBase, this, "Dispose");
486 }
487 }
static string InvalidScopeThread
Definition SR.cs:40
static string TransactionScopeIncorrectCurrent
Definition SR.cs:62
static string TransactionScopeInvalidNesting
Definition SR.cs:64
Definition SR.cs:7
static Thread CurrentThread
Definition Thread.cs:312
TransactionScope CurrentScope
Definition ContextData.cs:7
EnterpriseServicesInteropOption _interopOption
CommittableTransaction _committableTransaction
override bool Equals([NotNullWhen(true)] object? obj)

References System.Transactions.TransactionScope._committableTransaction, System.Transactions.TransactionScope._complete, System.Transactions.TransactionScope._dependentTransaction, System.Transactions.TransactionScope._disposed, System.Transactions.TransactionScope._expectedCurrent, System.Transactions.TransactionScope._interopOption, System.Transactions.TransactionScope._scopeThread, System.Transactions.TransactionScope._threadContextData, System.Transactions.TransactionScope.AsyncFlowEnabled, System.Transactions.TransactionException.CreateInvalidOperationException(), System.Transactions.ContextData.CurrentScope, System.Threading.Thread.CurrentThread, System.Transactions.Transaction.DistributedTxId, System.Transactions.TransactionTraceIdentifier.Empty, System.Transactions.Transaction.Equals(), System.Transactions.Transaction.FastGetTransaction(), System.Transactions.TransactionScope.InternalDispose(), System.Transactions.TransactionsEtwProvider.InvalidOperation(), System.Transactions.InvalidOperationException, System.SR.InvalidScopeThread, System.Diagnostics.Tracing.EventSource.IsEnabled(), System.Transactions.TransactionsEtwProvider.Log, System.Transactions.TransactionsEtwProvider.MethodEnter(), System.Transactions.TransactionsEtwProvider.MethodExit(), System.Transactions.TransactionScope.PopScope(), System.Transactions.Transaction.Rollback(), System.Transactions.TransactionsEtwProvider.TransactionScopeCurrentChanged(), System.SR.TransactionScopeIncorrectCurrent, System.SR.TransactionScopeInvalidNesting, System.Transactions.TransactionsEtwProvider.TransactionScopeNestedIncorrectly(), and System.Transactions.Transaction.TransactionTraceId.