tags:

views:

54

answers:

1

WPF VS 2010 C#

Have a window where the beginning of the code behind is to collect data for a view that take 45 secs or more...how would you do a please wait message that last until the view is collected. also, is there any way to have a wait cursor ?

+1  A: 

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.

HCL
nice, very nice thanks
ramnz
@ramnz: If this answer helped you, please mark it as the accepted answer by clicking the accept-checkmark. You find the checkmark directly under the voting-buttons.
HCL