Async WebClient is not really Async?

I created an asynchronous WebClient request inside the class as follows:

public class Downstream
    {
        public bool StartDownstream()
        {
            WebClient client = new WebClient();

            client.Headers.Add("user-agent", "Mozilla/4.0 [...]");
            client.Headers.Add("Content-Type","application/x-www-form-urlencoded");
            try
            {

                byte[] postArray = Encoding.UTF8.GetBytes("somevar=foo&someothervar=bar");
                Uri uri = new Uri("http://www.examplesite.com/somepage.php");

                client.UploadDataCompleted += 
                new UploadDataCompletedEventHandler(client_UploadDataCompleted);
                client.UploadDataAsync(uri, postArray);
            }
            catch (WebException e)
            {
                MessageBox.Show("A regular Web Exception");
            }
            catch (NotSupportedException ne)
            {
                MessageBox.Show("A super Web Exception");
            }
            return true;
        }

        void client_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
        {
            MessageBox.Show("The WebClient request completed");
        }
    }

Then I create a new instance of the class and run the method here:

Downstream Downstream1 = new Downstream();
Downstream1.StartDownstream();

When I do this, the thread in which the form is running seems to freeze until the WebClient gets a response. Why is this? I used a method UploadDataAsyncso that it is not asynchronous?

Edit:

This is my call stack:

    [External Code] 
>   Arcturus.exe!Arcturus.Downstream.StartDownstream() Line 36 + 0x18 bytes C#
    Arcturus.exe!Arcturus.MainWindow.btnLogin_Click(object sender, System.Windows.RoutedEventArgs e) Line 111 + 0x12 bytes  C#
    [External Code]

This is all that happens when I launch my application by simply hanging methods StartDownstream()and client.UploadDataAsync(uri, postArray);.

+5
source share
3 answers

WebClient , , , Async . BackgroundWorker.

!

+3

, STAThread, ? COM-, . , UploadDataAsync , , .

0

-, client.UploadDataAsync(uri, postArray). " .UploadDataAsync(uri, postArray);"

-, , async Task bool. async Task StartDownstream() {..}

, StardDownstream async . Downstream1.StartDownstream();

- , , .

-1

All Articles