0

I have a WCF SOA which makes many database calls which in turn is slowing down my View initialisation over http. I want to try to use async await on some of these methods:

 _CountryList = await GetCountries();

   private async Task<List<Countries>> GetCountries()
    {
        return _CountryList = await Task.Run(() => new List<Countries>(IsesService.GetArticleCountrys()));
        //_CountryList = new List<Countries>(IsesService.GetArticleCountrys());
    }

and finally, here is my method on the service being called by IsesService:

  public List<Countries> GetArticleCountrys()
    {
        var query = from c in _Context.tbCountrys
                    select new { c.regionCode, c.shortName };

        List<Countries> CountriesList = new List<Countries>();

        foreach (var c in query)
        {
            Countries country = new Countries()
            {
                regionCode = c.regionCode,
                shortName = c.shortName
            };

            CountriesList.Add(country);
        }

        return CountriesList;
    }

I'm getting an error: The await operator can only be used with an async method Sure I'm probably making a rookie mistake here?

Hardgraf
  • 2,566
  • 4
  • 44
  • 77

0 Answers0