P
P
p4p2013-04-10 21:28:49
.NET
p4p, 2013-04-10 21:28:49

How to get value from Task in c#

async Task<string> AccessTheWebAsync(int id)
        {

            HttpClient client = new HttpClient();
            string fields = "photo_big";
            Task<string> getStringTask = client.GetStringAsync("https://api.vk.com/method/users.get?uid=" + (string)ApplicationData.Current.LocalSettings.Values["id"] + "&fields=" + fields);


            string urlContents = await getStringTask;

  
            return urlContents;
        }


Returns 'System.Threading.Tasks.Task' and how to get the server's response?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
B
BaJlepa, 2013-04-10
@BaJlepa

Or use await
await AccessTheWebAsync(123);

L
LightSUN, 2013-04-10
@LightSUN

Call the Result property:

AccessTheWebAsync(123).Result

N
Nikolai Turnaviotov, 2013-04-13
@foxmuldercp

on tech days, it seems they recently posted a recording of a seminar on VS Day in the Kiev office of Microsof, there was a good lecture about asinka - from the series what it is and how to cook it, you go there. Sergei Baidachny read one of the lectures.

N
Nikolai Bogdanov, 2013-12-25
@konoplinovich

string s = await AccessTheWebAsync(123);or string s = AccessTheWebAsync(123).Result;. If the task has not completed, calling Result will block the current thread until the task completes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question