Is this a valid parallelism pattern with a System User Connection in Creatio?
Is the below a valid multithreading pattern in Creatio when requiring to use a System User Connection, given that the script task (in my case) has access to a UserConnection?
var appConnection = (AppConnection)UserConnection.AppConnection;
Terrasoft.Core.Tasks.Parallel.ForEach(batchedCustomersToUpdate, new Terrasoft.Core.Tasks.ParallelOptions { MaxDegreeOfParallelism = maxParallelism }, (batch, state, currentBatch) => {
var uc = appConnection.SystemUserConnection;
foreach(var customer in batch) {
var contact = uc.EntitySchemaManager
.GetInstanceByName("Contact")
.CreateEntity(uc);
if (contact.FetchFromDB(customer.customerId)) {
contact.SetColumnValue("UsrColumnName", customer.columnNameValue);
contact.SetColumnValue("UsrDateColumnName", uc.CurrentUser.GetCurrentDateTime());
contact.Save(false);
}
}
});From what I can tell, I think appConnection.SystemUserConnection gets a new SystemUserConnection instance each time it is called, but that's only from having a brief look at the decompiled code based on the method names, so I might be wrong.
I cannot find any examples online of correct multi-threaded usage of User Connections in a similar way, just warnings that a single instance should not be used in multiple threads due to them not being threadsafe. The only documentation I could find was for a fire-and-forget method of running parallel background operations, but in my case I needed the launching code to know when all child processes had finished so it wasn't a great solution for me: https://academy.creatio.com/guides/dev/development-on-creatio-platform/back-end-development/data-operations-back-end/execute-operations-in-the-background/overview
The above code in a script task does appear to run fine & perform the expected updates, but I wanted to check to see if it might cause unexpected intermittent issues?
Like