c# async method without a real await supported method called within it.

Have been searching for this since a long time. Finally found it:

http://stackoverflow.com/questions/15522900/how-to-safely-call-an-async-method-in-c-sharp-without-await

public async static Task<int> GetTwitterResultsCountAsync(string itemLink)
        {
            int returnCount = await Task.Run<int>(() =>
            {
                int count = 0;
 
                try
                {
                    count = (from search in TwitterLog.TwitterContext.Search
                             where search.Type == SearchType.Search &&
                                   search.Query == itemLink
                             select search).Count();
 
                    return count;
                }
                catch
                {
                    return count;
                }
            });
 
            return returnCount;
        }

Just a note - these methods work fine when called from a asp.net page. However, if you call it from a web service method even if you use .Result to call it synchronously, it does not work for some reason.

Comments

Popular posts from this blog

Enable Visual Studio to use more than 2GB of memory

Firefox and Chrome dark mode

Late 2008 Macbook only giving 1.5 gb/s speed with 6 gb/s Intel SSD?