0
トランザクションが完了したかどうかを判断しようとしていますが、結果によっては別のスレッドで他の処理をしたいと考えています。処理後の取引状況の確認
private static void ProcessActions()
{
while(true)
{
action = pendingActions[0];
if (action.CurrentTransaction == null ||
action.CurrentTransaction.TransactionInformation.Status == TransactionStatus.Committed)
{
// Proceed to do things!!
remove = true;
}
else if (action.CurrentTransaction.TransactionInformation.Status == TransactionStatus.Aborted)
{
// Transaction has aborted. Remove this action from the list
remove = true;
}
if (remove)
{
lock (pendingActions)
{
pendingActions.Remove(action);
eventCount = pendingActions.Count;
}
}
}
}
私が設定:別のスレッドで、私は類似の取引を持っているオブジェクトのリストを通過しています、別のクラスでは、今
using (TransactionScope scope = new TransactionScope())
{
// Do stuff
Scope.Complete();
}
:
は、以下のTransactionScopeを考えてみましょうコンストラクタで新しいアクションを作成しているときのアクションのCurrentTransaction:public Action()
{
CurrentTransaction = System.Transactions.Transaction.Current;
}
問題は、他のスレッドがアクションを処理しているときに、action.CurrentTransactionが破棄され、System.ObjectDisposedExceptionがスローされることです。
アクション内の各トランザクションのステータスを把握するにはどうすればよいですか?
達成しようとしていることはありますか? – VMAtm
@ VMAtm私は単に、各アクションのトランザクションがまだ処理中であるか、中断しているのか、コミットしているのかを確認してから、他のアクションを実行することを確認したかっただけです。私は解決策を見つけたと思う。下の私の答えをチェックしてください。 –