Y
Y
Yahya2015-04-14 13:55:28
ASP.NET
Yahya, 2015-04-14 13:55:28

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";
        }

Or maybe I'm wrong, point in which direction to move?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question