I have written a code to crunch some data on Azure server. The first time that I wrote the code, it was linear For Each loop and would take forever to be finished, I improved the code by using Parallel as it follows :
Parallel.ForEach(users, currentUser =>
{
int number = myrollup.CountFilmsForUsers(currentUser.UserId,distort,tend).Result;
lock(myrollup)
{
var record = new UserAnalytics();
{
UserId = currentUser.UserId,
UserFName = currentUser.FirstName,
UserLName = currentUser.LastName,
};
session.SaveOrUpdate(record);
}
});
This parallel loop does the job in 9 min, however I want to improve this more by using a Producer / Consumer pattern. Any ideas on how to do this with Nhibernate in C#?