我有一個TransactionScope對象,我想將它用於使用Parallel.ForEach創建的所有任務,我該如何實現這一點?如何通過一組並行任務共享事務
我想編寫並行消息隊列,20-50的消息,消息隊列是事務性的:
using (var queue = new MessageQueue(_exportEndpoint))
{
var label = string.Format("{0} ComponentId - {1}", DateTime.Now.ToUniversalTime(), componentId);
queue.Send(contents, label, MessageQueueTransactionType.Automatic);
_log.WriteInfo("ExportToQueue: Message sent to queue - " + label);
}
和主線程使用一個TransactionScope對象,我嘗試以下,但我得到一個超時交易提交:
var clone = Transaction.Current.DependentClone(DependentCloneOption.RollbackIfNotComplete);
Parallel.ForEach(components.ToList(), c => ExportComponent(c, clone));
你嘗試過什麼到目前爲止一個
Complete
?你有一些你想要完成的代碼示例嗎? – 2010-08-20 15:32:01