views:

68

answers:

2

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:

alt text

Also, checkout:

KMan
Liking the use of Paralell.ForEach ;)
Sascha
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
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