I am using a Parallel.ForEach loop in C# / VS2010 to do processing and I have a couple of questions.
First of all I have a process that needs to extract information from a remote webservice and then needs to build images (GDI) on the fly.
I have a class that encapsulates all of the functionality into a single object with two main methods Load() and CreateImage() with all the GDI management / WebRequests "blackboxed" inside this object.
I then create a GenericList that contains all the objects that need to be processed and I iterate through the list using the following code:
try
{
Parallel.ForEach(MyLGenericList, ParallelOptions, (MyObject, loopState) =>
{
MyObject.DoLoad();
MyObject.CreateImage();
MyObject.Dispose();
if (loopState.ShouldExitCurrentIteration || loopState.IsExceptional)
loopState.Stop();
});
}
catch (OperationCanceledException ex)
{
// Cancel here
}
catch (Exception ex)
{
throw ex;
}
Now my questions are:
Thanks in advance :) Адам