Answer the question
In order to leave comments, you need to log in
How to properly notify the main thread?
Good afternoon!
Prompt as it is correct to notify the main flow from another. Here is my code:
protected void Button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(DownloadFile);
thread.Start();
}
public void DownloadFile()
{
string path = TextBox1.Text;
string uriName = Path.GetFileName(path);
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += WebClientOnDownloadFileCompleted;
webClient.DownloadFileAsync(new Uri(path), @"D:\Download\" + uriName);
}
private void WebClientOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs asyncCompletedEventArgs)
{
Label1.Text = "Complete";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question