private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { FileInfo[] files = (FileInfo[])e.Argument; BackgroundWorker worker = (BackgroundWorker)sender; int filesprogressed = 0; foreach (FileInfo file in files) { try { PassedObject po = new PassedObject(); po.bmp = new Bitmap(file.FullName); po.fileinfo = file; if (worker.CancellationPending) { e.Cancel = true; return; } filesprogressed++; worker.ReportProgress(filesprogressed, po); } catch (Exception exc) { MessageBox.Show(exc.Message); } } }
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { PassedObject po = (PassedObject)e.UserState; imageList48.Images.Add(po.fileinfo.FullName, getThumbnail(po.bmp, 48, 48)); imageList64.Images.Add(po.fileinfo.FullName, getThumbnail(po.bmp, 64, 64)); imageList96.Images.Add(po.fileinfo.FullName, getThumbnail(po.bmp, 96, 96)); imageList128.Images.Add(po.fileinfo.FullName, getThumbnail(po.bmp, 128, 128)); imageList256.Images.Add(po.fileinfo.FullName, getThumbnail(po.bmp, 256, 256)); uiTexturesListView.Items[po.fileinfo.FullName].ImageKey = po.fileinfo.FullName; uiTexturesListView.Items[po.fileinfo.FullName].ToolTipText = po.fileinfo.Name + " (" + po.bmp.Width.ToString() + " x " + po.bmp.Height.ToString() + ")"; /*ListViewItem lvi = new ListViewItem(); * lvi.Name = po.fileinfo.FullName; * lvi.Text = po.fileinfo.Name; * lvi.ImageKey = po.fileinfo.FullName; * lvi.Tag = "file"; * lvi.ToolTipText = po.fileinfo.Name + " (" + po.bmp.Width + " x " + po.bmp.Height + ")"; * listView1.Items.Add(lvi); * */ toolStripStatusLabel1.Text = e.ProgressPercentage.ToString(); }