我有一个附加到 DataGridView 上的 selectionChanged 事件的事件处理程序。在这个处理程序中,我需要创建和加载图像,然后将其显示在图片框中。我遇到的麻烦是,如果我在行选择之间快速跳转,应用程序似乎会挂起,这是我试图避免的问题。
这是我的代码:
private void loadJobSheet(Job currentJob)
{
if (this.jobCardImageThread != null && this.jobCardImageThread.IsAlive)
this.jobCardImageThread.Abort();
Image jobCardImage = null;
this.jobCardImageThread = new Thread(new ThreadStart(
delegate()
{
SavedDocument document = currentJob.SavedDocument;
DocumentConverter<Bitmap> converter = DocumentConverterFactory<Bitmap>.getDocumentConverterForType(Path.GetExtension(document.Document_Name).Replace('.', ' ').Trim().ToUpper(), typeof(Bitmap));
jobCardImage = (Image)converter.convertDocument(FileUtils.createTempFile(document.Document_DocumentData.ToArray(), document.Document_Name));
}
));
jobCardImageThread.Start();
this.picLoadingJobCard.Visible = true;
jobCardImageThread.Join();
if (jobCardImage != null)
{
this.picJobCard.Image = jobCardImage;
this.picLoadingJobCard.Visible = false;
}
}