Load the data in a BackgroundWorker. Use the BackroundWorkers ProgressChanged
-event to show progress message.
// Show here your wait message make a ProgressBar visible
Mouse.OverrideCursor = Cursors.Wait; // Maybe you only want to set the cursor of the window. Then change this line code (and the reset)
BackgroundWorker bgWorker = new BackgroundWorker() { WorkerReportsProgress=true};
bgWorker.DoWork += (s, e) => {
// Load here your file/s
// Use bgWorker.ReportProgress(); to report the current progress
};
bgWorker.ProgressChanged+=(s,e)=>{
// Here you will be informed about progress and here it is save to change/show progress. You can access from here savely a ProgressBars or another control.
};
bgWorker.RunWorkerCompleted += (s, e) => {
// Here you will be informed if the job is done. Close here your wait message or hide your progressbar
Mouse.OverrideCursor = null;
};
bgWorker.RunWorkerAsync();
Because the loading operation now runs async, you have to make sure that your UI does not allow the user to do things that are invalid in the current application state (loading). The most simple possibility to do this, is to disable the window with the IsEnabled
-property set to false
.