I have a static method that in it I call async method (xmlHelper.LoadDocument()). and I call this method in a property at Setter section
internal static IEnumerable<Word> LoadTenWords(int boxId)
{
XmlHelper xmlHelper = new XmlHelper();
XDocument xDoc = xmlHelper.LoadDocument().Result;
return xDoc.Root.Descendants("Word").Single(...)
}
As you know LoadTenWord is static and cannot be a async method, so I call LoadDocument with Result property. When I run my app the application don’t work but when I debug it and I wait in following line
XDocument xDoc = xmlHelper.LoadDocument().Result;
everything is ok!!! I think, without await keyword, C# doesn’t wait for the process completely finished.
do you have any suggestion for solving my problem?
The fact that the method is
staticdoes not mean it can’t be marked asasync.Using
Resultresults in the method blocking until the task is completed. In your environment that’s a problem; you need to not block but merelyawaitthe task (or use a continuation to process the results, butawaitis much easier).