在为我的项目实现导出 util 的过程中,我遇到了上传文件期间阻止 UI 的问题。基本上问题是在异步任务期间我无法更新进度栏。
我已经尝试了几种解决方案。一般来说,当我调用exportPopUp.ShowDialog()时,它会阻止copyAttachment()的执行,并且整个逻辑在关闭表单后完成。我决定使用 Show() 但当我这样做时,表单不存在(全灰色)
这是我的背景逻辑:
private void exportButton_Click(object sender, EventArgs e)
{
// get files
int row = reportsDataGrid.CurrentCell.RowIndex;
if (row >= 0)
{
string problemId = reportsDataGrid.Rows[row].Cells[0].Value.ToString();
AC.Trace.I("Problem Id", problemId);
FolderBrowserDialog dlgFolderBrowser = new FolderBrowserDialog();
dlgFolderBrowser.Description = "Select folder to save Report files!";
DialogResult result = dlgFolderBrowser.ShowDialog();
if (result == DialogResult.OK)
{
string folderName = dlgFolderBrowser.SelectedPath;
AC.Trace.I("Destination folder name", folderName);
CIS.PRS.Data.Attachments attachments = jampPrsService.ReportFiles(problemId);
processAttachments(attachments, folderName, problemId);
}
}
}
private async void processAttachments(Attachments attachments, string folderName, string problemId)
{
this.exportPath = folderName + "\\" + problemId;
cts = new CancellationTokenSource();
this.exportPopUp = new exportPopUp(attachments.Size(), cts);
this.exportPopUp.ExportFinished += ExportPopUp_ExportFinished;
exportPopUp.setExportLabelText("Exporting problem report " + problemId);
exportPopUp.ShowDialog();
await copyAttachments(attachments, folderName, problemId);
}
一般来说,整个逻辑按我的预期工作,但我无法同时复制任务和更新进度栏。提前致谢
翻阅古今
相关分类