I'd like to download a picture and afterwards show it in a picturebox.
at first I did like this:
WebClient client = new WebClient();
client.DownloadFile(url, localFile);
pictureBox2.Picture = localFile;
But that wasn't perfect because for the time while the download is performed the app is kinda freezing.
Then I changed to this:
public class ParamForDownload
{
public string Url { get; set; }
public string LocalFile { get; set; }
}
ParamForDownload param = new ParamForDownload()
{
Url = url,
LocalFile = localFile
};
ThreadStart starter = delegate { DownloadMap (param); };
new Thread(starter).Start();
pictureBox2.Picture = localFile;
private static void DownloadMap(ParamForDownload p)
{
WebClient client = new WebClient();
client.DownloadFile(p.Url, p.LocalFile);
}
But now I have to do something like a "wait for thread ending" because the file is accessed in the thread and to same time there's downloaded something to the file by the DownloadMap method.
What would be the best wait to solve that problem?