Hello,
Can someone help me with best practice when using CMSTransactionScope and CMSConnectionScope within an import using the CMSParallel library?
I'm thinking this is the correct way, but can someone tell me if i'm wrong? Basically I am importing lots of collections of data and if there is an error rollback otherwise commit the transaction.
var data1 = new List<string>();
var data2 = new List<string>();
try {
using (var trans = new CMSTransactionScope()) {
CMSParallel.ForEach(data1, obj => {
using (new CMSConnectionScope()) {
// ... insertion logic ..
}
});
CMSParallel.ForEach(data2, obj => {
using (new CMSConnectionScope()) {
// ... insertion logic ..
}
});
trans.Complete();
}
} catch (Exception ex) {
// ... handle exception ...
}
Please let me know what you think and if there is a better approach? I am also wondering that. If there is a transaction on the main thread, would this cause subsequent connections in the parallel loop to timeout/deadlock.
Best Regards,