Hi, I am generating the thumbnails of various image file, now I want to optimize it using thread or queue. so when I select a folder it generate thumb image one by one like in windows search. I am new to C#, please help me on this. Thanks, Tanmoy
+6
A:
You can use Task Parallel Library to achieve that. Something like:
Also, checkout:
KMan
2010-10-05 06:54:19
Liking the use of Paralell.ForEach ;)
Sascha
2010-10-05 07:04:24
Yes, Parallelizing seems the way to go. Try this search also if you dont have .net4 yet or if you prefer not to use a additional library http://stackoverflow.com/search?q=parallelize+c%23
controlbreak
2010-10-05 07:09:30
A:
I would use the BackgroundWorker
class (also see this tutorial) to generate the thumbnails in the background. Something like:
BackgroundWorker imageGenerator = new BackgroundWorker()
foreach(var filename in imageFileNames)
{
imageGenerator.DoWork += (s, a) => GenerateThumbnailMethod(filename);
}
imageGenerator.RunWorkerAsync();
This will generate the thumbnails on a separate thread. You can also get the BackgroundWorker
to let you know when it's done by assigning an event handler to its RunWorkerCompleted
event. You should do this, because this allows for error checking, as the RunWorkerCompletedEventArgs
object has an Error property.
Matt Ellen
2010-10-05 07:06:27