我有一个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