I am running a .NET 4.7 C# console application in which I am iterating through a collection of files (list of strings with file paths.
I want to run an operation on each file in parallel.
private void LaunchComparators()
{
//1) Get Trade Files
var files = GetTradeFiles();
//2) Run comparisons
try
{
Parallel.ForEach(files, file => LaunchComparator(file));
}
catch (Exception ex)
{
Log.Error(ex.Message);
throw ex;
}
//2 Write Results
WriteResults();
}
private void LaunchComparator(string file)
{
var comparator = new TradeComparator();
var strategyComparisonOutput = comparator.ComparePerStrategy(file);
}
While running the comparison, the first comparison completes and then the program abruptly stops without any exceptions.
I am not sure what I should do differently here, so that the files are all processed individually.
I am new to parallel programming/threading. Any help appreciated.