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 dinhPosted Apr 15, 2009, 7:30 PM
Func
fileDownload.BeginInvoke("url",new AsyncCallback(FileDownloadCallback),fileDownload);
private void FileDownloadCallback(IAsyncResult result)
{
Func
string fileContent = fileDownload.EndInvoke(result);
}
Pieter De DeckerPosted Apr 16, 2009, 4:27 AM
Ashley ArgilePosted Apr 15, 2009, 5:27 PM
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