您好,我在檔案對話框中遇到問題
標準代碼,但在選擇大檔案時它會凍結(我需要先重新格式化為 xlsb 的 600MB xls檔案,然后從中流式傳輸資料,但這在這里并不重要)。
我想要實作的是在單擊Open按鈕時隱藏對話框,以便我可以顯示Loading Message。
但我不確定我該如何實作。我可以以某種方式訂閱“打開”按鈕嗎?
OpenFileDialog openFile = new OpenFileDialog() { DereferenceLinks = false };
openFile.Title = "Select Supplier List";
openFile.Filter = "Excel files (*.*xls*)|*.*xls*";
try
{
if (openFile.ShowDialog() == true)
{
/* Takes long time to go after selection */
ViewModel.ReportPath = openFile.FileName;
ViewModel.FileTrueName = Path.GetFileName(ViewModel.ReportPath);
}
}
catch
{
ViewModel.ReportPath = null;
ViewModel.FileTrueName = null;
}
uj5u.com熱心網友回復:
用任務包裝代碼,幫助:) 在搜索答案期間發生了一些變化,基于評論。
Task.Run(() =>
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Title = "Select Supplier List";
openFile.Filter = "Excel Files(*.xls; *.xlsx; *.xlsb; *.xlsm)| *.xls; *.xlsx; *.xlsb; *.xlsm";
try
{
if (openFile.ShowDialog() == true)
{
ViewModel.ReportPath = openFile.FileName;
ViewModel.FileTrueName = Path.GetFileName(ViewModel.ReportPath);
}
}
catch
{
ViewModel.ReportPath = null;
ViewModel.FileTrueName = null;
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/516415.html
