I am writing a small file download utility. The DownloadFile() method is called on Window_Loaded() event of my MainWindow. Since the DownloadFile method is resource intensive, the MainWindow does not finish rendering on screen when the download starts. It is just after the download is finished that I come to see the actual controls on my WPF Form.
To control this, I am using following DoEvents() code, but still it is not working. I am calling this function after InitializeComponent() in the Form constructor and just before calling DownloadFile() in the Window_Loaded event.
private void DoEvents()
{
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
new Action(delegate { }));
}