I would like to upload a picture and then show it in the picture.
I liked this at first:
WebClient client = new WebClient();
client.DownloadFile(url, localFile);
pictureBox2.Picture = localFile;
But that was not the case, because at the time the download was in progress, the application freezes.
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 "wait for thread end", because the file is accessed in the stream and at the same time I downloaded something to the file using the DownloadMap method.
What is the best way to wait to solve this problem?
source
share