I wrote a little program that converts a bunch of files to pdf.
The program does the following:
- Get an Array of
FileInfoobjects from a Folder (10'000 docs) - For each
FileInfo- Create a backup copy with
FileInfo.CopyTo(), - Convert the Document to PDF by using some Aspose Libraries
- After conversion, copy the PDF to a new destination
- Inside the foreach an Event is raised and handled by a WinForm UI to show some progress
- Create a backup copy with
Depending on the size of the Document the conversion of a Document can take 0-3 seconds.
I thought that would be a perfect candidate for Parallel.ForEach, so I modified the program.
However the conversion took instead of 1 hour with conventional foreach 1.5 hours with Parallel.Foreach (The Server I've tried it has 2 x Intel Xeon Procs).
What did I do wrong or what do I need to consider to get better performance?