SHOW:
|
|
- or go back to the newest paste.
1 | ResponseFetcher.cs: | |
2 | ||
3 | - | public Task<T> GetApiResponse(string url) |
3 | + | public Task<T> GetApiResponseAsync(string url) |
4 | { | |
5 | - | return new Task<Task<T>>(async() => { |
5 | + | using (var client = new HttpClient()) { |
6 | - | using (var client = new HttpClient()) { |
6 | + | |
7 | var response = await client.GetAsync(url).ConfigureAwait(false); | |
8 | - | var response = await client.GetAsync(url).ConfigureAwait(false); |
8 | + | var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); |
9 | - | var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false); |
9 | + | |
10 | return JsonConvert.DeserializeObject<T>(content); | |
11 | - | return JsonConvert.DeserializeObject<T>(content); |
11 | + | } |
12 | - | } |
12 | + | |
13 | - | }).Unwrap(); |
13 | + | |
14 | --------------------- | |
15 | LoginViewModel.cs: | |
16 | ||
17 | - | BaseViewModel.cs: |
17 | + | |
18 | ||
19 | - | Method that runs the task: |
19 | + | |
20 | ||
21 | - | public async Task RunTask (Task task) |
21 | + | await task.GetApiResponseAsync("api/accounts/verify?username=test&password=test"); |
22 | ||
23 | - | await Task.Run (() => { |
23 | + |