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
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
Post a Comment