Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:13
professionalSascha Lefèvre4-Nov-17 7:13 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:22
alin14-Nov-17 7:22 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:25
professionalSascha Lefèvre4-Nov-17 7:25 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:30
alin14-Nov-17 7:30 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:39
professionalSascha Lefèvre4-Nov-17 7:39 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:41
alin14-Nov-17 7:41 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:55
professionalSascha Lefèvre4-Nov-17 7:55 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 8:23
alin14-Nov-17 8:23 
I declared a global const int batchSize = 10 and a global variable counter.

BackgroundWorker1DoWork sends a new batch of thumbnails every batchSize times or if the i counter already reached the limit (fileList.Count - 1):
void BackgroundWorker1DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
    List<Bitmap> thumbnailList = new List<Bitmap>();

    for (var i = 0; i < fileList.Count; i++)
    {
        Bitmap thumbnail = MakeThumbnail(fileList[i], 200, 200);
        thumbnailList.Add(thumbnail);

        if (((thumbnailList.Count == batchSize) && (batchSize < fileList.Count)) ||
            (i == (fileList.Count - 1)))
        {
            backgroundWorker1.ReportProgress(i, thumbnailList);
            thumbnailList.Clear();
        }
    }
}


And the second function:
void BackgroundWorker1ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
    List<Bitmap> list = (List<Bitmap>)e.UserState;
    listView1.BeginUpdate();

    if (list.Count > 0)
    {
        foreach (Bitmap tn in list)
        {
            imageList1.Images.Add(tn);
            ListViewItem caption = new ListViewItem(Path.GetFileName(fileList[counter]));
            caption.ImageIndex = counter;
            listView1.Items.Add(caption);
            counter++;
        }
    }

    listView1.EndUpdate();
}


Unfortunatelly it doesn't work. thumbnailList.Count from the second function reports 0, so apparently thumbnailList.AddRange((List<Bitmap>)e.UserState); is one of the problems. Any ideas?

PS: I uploaded the test project here: TinyUpload.com[^] If you want to test it, drag and drop pictures over the form.

modified 4-Nov-17 16:37pm.

GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 8:29
professionalSascha Lefèvre4-Nov-17 8:29 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin15-Nov-17 2:41
alin15-Nov-17 2:41 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre5-Nov-17 2:53
professionalSascha Lefèvre5-Nov-17 2:53 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin15-Nov-17 3:09
alin15-Nov-17 3:09 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre5-Nov-17 3:43
professionalSascha Lefèvre5-Nov-17 3:43 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin15-Nov-17 4:58
alin15-Nov-17 4:58 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin15-Nov-17 13:22
alin15-Nov-17 13:22 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre5-Nov-17 20:52
professionalSascha Lefèvre5-Nov-17 20:52 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin16-Nov-17 2:56
alin16-Nov-17 2:56 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre6-Nov-17 3:00
professionalSascha Lefèvre6-Nov-17 3:00 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Gerry Schmitz4-Nov-17 7:39
mveGerry Schmitz4-Nov-17 7:39 
QuestionRun List Of Tasks Sequentially and Process Them As The Complete Pin
Kevin Marois1-Nov-17 8:47
professionalKevin Marois1-Nov-17 8:47 
AnswerRe: Run List Of Tasks Sequentially and Process Them As The Complete Pin
ZurdoDev1-Nov-17 9:37
professionalZurdoDev1-Nov-17 9:37 
AnswerRe: Run List Of Tasks Sequentially and Process Them As The Complete Pin
Sascha Lefèvre1-Nov-17 10:31
professionalSascha Lefèvre1-Nov-17 10:31 
AnswerRe: Run List Of Tasks Sequentially and Process Them As The Complete Pin
BillWoodruff2-Nov-17 17:56
professionalBillWoodruff2-Nov-17 17:56 
AnswerRe: Run List Of Tasks Sequentially and Process Them As The Complete Pin
MadMyche14-Nov-17 8:35
professionalMadMyche14-Nov-17 8:35 
QuestionC#+WebBrowser+JavaScript - full download Pin
kama_kama31-Oct-17 12:03
kama_kama31-Oct-17 12:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.