Hi,
I am loading the images using the BackgroundThread. I am receving "nullreferenceexception unhandled by user code" after loading all the images into the Listview. What could be the issue? Please let me know.
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
try
{
int progress = 0;
string pname;
Image myImage;
max_length = files.Length;
for (int k = 0; k < files.Length; k++)
{
ProgressInfo info = new ProgressInfo();
pname = System.IO.Path.GetFullPath(files[k]);
myImage = Image.FromFile(pname);
info.Image = myImage;
info.ImageIndex = k;
backgroundWorker1.ReportProgress(progress, info);
myImage = null;
}
}
catch (Exception ex)
{
throw ex.InnerException;
}
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
try
{
//Get image.
ProgressInfo img = e.UserState as ProgressInfo;
//Set image to ListView here.
ImgListView.Images.Add(getThumbnaiImage(ImgListView.ImageSize.Width, img.Image));
fname = System.IO.Path.GetFileName(files[img.ImageIndex]);
ListViewItem lvwItem = new ListViewItem(fname, img.ImageIndex);
lvwItem.Tag = files[img.ImageIndex];
lstThumbNailView.Items.AddRange(new ListViewItem[] { lvwItem });
percent = (int)((float)100 * (float)i / (float)files.Length);
this.progressBar1.Value = (int)percent;
this.label1.Text = "Loading images...";
}
catch (Exception ex)
{
throw ex.InnerException;
}
}