I am using a graphicmagick.exe (command tool) to convert the file from one format to another format: In that, I used to pass input path and output path for conversion as aruguments. Now I am looping a directory using foreach and passing the input file one by one and converting to another format.
But it affects the performance. Is there any better way to increase the performance? Please suggest me.
Use Parallel class (ForEach or For).
Parallel.ForEach(files, file =>
// do something with file
In that case all your processor cores will be loaded. Otherwise just one. But remember, that you code inside Parallel blocks must be thread-safe and not to block each-other.
I think your code executes the application on each for. So, it's very expensive. The application has options for multiple file handling. Check first that, instead of a code that execute the application, for every file. Is different to start one process and apply changes on the image than starting one process per file.
If you still need to execute on C#, change your code to use Parallel.Foreach instead of foreach and check if there is a gain in the execution. Try with a sample, maybe 50-100 files in a directory and check execution time between both implementations.
Greetings and good luck!