Generate thumbnails using in C#
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 开发者_如何学Pythonme on this. Thanks, Tanmoy
You can use Task Parallel Library to achieve that. Something like:
Also, checkout:
- How to: Create Thumbnail Images
- How To: Creating Thumbnail Images
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.
精彩评论