خرید بک لینک

Vote count: 0

So I'm trying to write a simple universal app to get the price of bitcoin from the web. I have an async method that I got from here to get the json from a url and put it into a string. Here is where I called the method:

        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            CoinPriceBackend CP = new CoinPriceBackend();

            string response = await GetFromAPI();
        }

And this is the method:

        async Task<string> GetFromAPI()
        {
            try
            {
                //Create HttpClient
                HttpClient httpClient = new HttpClient();

                //Define Http Headers
                httpClient.DefaultRequestHeaders.Accept.TryParseAdd("application/json");

                //Call
                string ResponseString = await httpClient.GetStringAsync(
                    new Uri("https://api.bitcoinaverage.com/ticker/GBP/"));
                //Replace current URL with your URL

                retu ResponseString;
            }

            catch (Exception ex)
            {
                retu "ERROR: " + ex;
            }
        }

I get the error

'The 'await' operator can only be used within an async method. 
Consider marking this method with the 'async' modifier and changing its retu type to 'Task'.'

But the method is async... How can I fix this?

Thanks!

asked 33 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 23 خرداد 1395 ساعت: 15:04

صفحه بندی