0

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 { }));
        }
RKh
  • 13,818
  • 46
  • 152
  • 265

3 Answers3

1

Have a look at the DownloadFileAsync method.

Jens
  • 25,229
  • 9
  • 75
  • 117
0

You should use BeginInvoke instead (with the Background option) and put the DownloadFile there.

Eddie Paz
  • 2,219
  • 16
  • 11
  • I am using a third-party tool. It does have FileAsync method, but still the same problem. – RKh Jul 27 '11 at 06:39
0

it is always suggested to do all the server hits and download related things in a separate thread. You can see how to that in following link.

http://bathinenivenkatesh.blogspot.com/2011/07/wpf-build-more-responsive-ui.html

Bathineni
  • 3,436
  • 18
  • 25