Currently, I can do
string strXMLfile = FileDownload("http://link/to/some/xml/file");
to download the contents of a file into a string. Is there a way to execute the file download in a BackgroundWorker and still have the method FileDownload return the contents of the requested file?
Loading

tim dinh16 reputationPosted Apr 15, 2009, 3:30 PM EDT
Func
fileDownload.BeginInvoke("url",new AsyncCallback(FileDownloadCallback),fileDownload);
private void FileDownloadCallback(IAsyncResult result)
{
Func
string fileContent = fileDownload.EndInvoke(result);
}
Ashley Argile97 reputationPosted Apr 15, 2009, 1:27 PM EDT
Add a backgroundWorker and handle the following events..
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
file = FileDownload((string)e.Argument);
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
MessageBox.Show(file);
}
start the download with - backgroundWorker1.RunWorkerAsync("http://link/to/some/xml/file");
Store the output of FileDownload in a local variable and retrieve it when the RunWorkerCompleted event fires.
Hope this helps..
regards
Ashley
Pieter De Decker22 reputationPosted Apr 16, 2009, 12:27 AM EDT