From 7febb144beff2ef9e52694d97bb24b8f6a7d75ac Mon Sep 17 00:00:00 2001 From: Richard Ross Date: Fri, 9 Oct 2015 11:59:20 -0700 Subject: [PATCH] Fix deadlock in WinRT platform utils when AppName is accessed from the main thread. This could happen because by default, `await` continues on the thread it was invoked from, in this case, the main thread, which is blocked on the line below. Fixes #26. --- Parse/PlatformHooks.WinRT.cs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Parse/PlatformHooks.WinRT.cs b/Parse/PlatformHooks.WinRT.cs index cb4ddb74..9f590c25 100644 --- a/Parse/PlatformHooks.WinRT.cs +++ b/Parse/PlatformHooks.WinRT.cs @@ -55,24 +55,19 @@ public string SDKName { public string AppName { get { - var result = new TaskCompletionSource(); - Action toRun = (async () => { - var file = await Package.Current.InstalledLocation.GetFileAsync("AppxManifest.xml"); - string manifestXml = await FileIO.ReadTextAsync(file); - - var doc = XDocument.Parse(manifestXml); - var installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation; + var task = Package.Current.InstalledLocation.GetFileAsync("AppxManifest.xml").AsTask().OnSuccess(t => { + return FileIO.ReadTextAsync(t.Result).AsTask(); + }).Unwrap().OnSuccess(t => { + var doc = XDocument.Parse(t.Result); // Define the default namespace to be used var propertiesXName = XName.Get("Properties", "http://schemas.microsoft.com/appx/2010/manifest"); - var displayNameXName = XName.Get("DisplayName", "http://schemas.microsoft.com/appx/2010/manifest"); - - result.TrySetResult(doc.Descendants(propertiesXName).Single().Descendants(displayNameXName).Single().Value); - }); - toRun(); - result.Task.Wait(); - - return result.Task.Result; + var displayNameXName = XName.Get("DisplayName", "http://schemas.microsoft.com/appx/2010/manifest"); + + return doc.Descendants(propertiesXName).Single().Descendants(displayNameXName).Single().Value; + }); + task.Wait(); + return task.Result; } }