Tanmoy Mitra
Tanmoy Mitra

Reputation: 61

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 me on this. Thanks, Tanmoy

Upvotes: 1

Views: 855

Answers (2)

Kamran Khan
Kamran Khan

Reputation: 9986

You can use Task Parallel Library to achieve that. Something like:

alt text

Also, checkout:

Upvotes: 6

Matt Ellen
Matt Ellen

Reputation: 11592

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.

Upvotes: 0

Related Questions