I use the routine below to process a group of videos from a directory:
AllVideos = new List<MyVideo>();
for (int i = 0; i < AllVideosFileNames.Length; i++)
{
MyVideo CurrentVid = new MyVideo(AllVideosFileNames[i], false);
CurrentVid.PopulateAllFrames();
CurrentVid.PopluateTestFrames();
CurrentVid.NormalizeTestFrames();
AllVideos.Add(CurrentVid);
}
I would like to process several videos at the same time, in parallel and save time. I tried to do this:
for (int i = 0; i < AllVideosFileNames.Length; i++)
{
Thread TempThread = new Thread(() =>
{
MyVideo CurrentVid = new MyVideo(AllVideosFileNames[i], false);
CurrentVid.PopulateAllFrames();
CurrentVid.PopluateTestFrames();
CurrentVid.NormalizeTestFrames();
AllVideos.Add(CurrentVid);
});
TempThread.Start();
}
However, this is so fast and literally does nothing. I do not mean anything when passing through the code, it is AllVideosempty when the loop completes execution.
Any ideas for a better design? or fix? Please thanks.
source
share