private void FScanProgress_Shown(object sender, EventArgs e) { EventLoop.DoAsync(wia => { try { if (wia.Item != null) { var imageFile = (ImageFile)wia.Item.Transfer(Format); if (imageFile != null) { ImageStream = new MemoryStream((byte[])imageFile.FileData.get_BinaryData()); } } } catch (Exception ex) { Exception = ex; } Invoke(new MethodInvoker(() => { DialogResult = cancel ? DialogResult.Cancel : DialogResult.OK; isComplete = true; Close(); })); }); }