private UIObject LaunchApp() { UIObject coreWindow = null; // Launch sometimes times out but the app is just slow to launch and Launch has what appears to be // a 5-second timeout built in. 5 seconds isn't always enough in VM scenarios. If we try again, // Launch will see that the app is already running and move on. const int MaxLaunchRetries = 5; for (int retries = 1; retries <= MaxLaunchRetries; ++retries) { try { Log.Comment("Attempting launch, try #{0}...", retries); if (_isPackaged) { coreWindow = _isUWPApp ? LaunchUWPApp() : LaunchNonUWPApp(_packageName); } else { using (AppLaunchWaiter launchWaiter = new AppLaunchWaiter(_windowCondition)) { string unpackagedExeFullPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), _unpackagedExePath); Process.Start(unpackagedExeFullPath); launchWaiter.Wait(); coreWindow = launchWaiter.Source; } } Log.Comment("Launch successful!"); break; } catch (Exception ex) { Log.Comment("Failed to launch app. Exception: " + ex.ToString()); if (retries < MaxLaunchRetries) { Log.Comment("UAPApp.Launch might not have waited long enough, trying again {0}", retries); Thread.Sleep(TimeSpan.FromSeconds(10)); // Give a healthy wait time. } else { Log.Comment("Dumping UIA tree..."); LogDumpTree(); Log.Error("Could not launch app {0} with top-level window condition '{1}'!", _appName, CreateTopLevelWindowCondition().ToString()); throw; } } } return(coreWindow); }
public static UIObject LaunchEx(string appName, UICondition topLevelWindowCondition) { Log.Out(msg: "Launch"); UIObject source; using (var appLaunchWaiter = new AppLaunchWaiter(topLevelWindowCondition: topLevelWindowCondition)) { AppStateManagementUtils.LaunchApplication(AumId: appName); appLaunchWaiter.Wait(); source = appLaunchWaiter.Source; } return(GetTopLevelUIObject(topWindow: source)); }
public static UIObject Launch(string appName, UICondition topLevelWindowCondition) { Log.Out(msg: nameof(Launch)); UIObject source; using (var appLaunchWaiter = new AppLaunchWaiter(topLevelWindowCondition: topLevelWindowCondition)) { new ApplicationActivationManager().ActivateApplication(appUserModelId: appName, arguments: null, options: ActivateOptions.None, processId: out var _); appLaunchWaiter.Wait(); source = appLaunchWaiter.Source; } return(GetTopLevelUIObject(topWindow: source)); }
public static UIObject LaunchForProtocol( string appName, string uri, UICondition topLevelWindowCondition) { Log.Out(msg: nameof(LaunchForProtocol)); var riid1 = new Guid(g: "43826d1e-e718-42ee-bc55-a1e261c37bfe"); IShellItem shellItem; SHCreateItemFromParsingName(path: uri, pbc: IntPtr.Zero, riid: ref riid1, shellItem: out shellItem); var riid2 = new Guid(g: "b63ea76d-1f85-456f-a19c-48159efa858b"); IShellItemArray ppenum; STORAGE_SHCreateShellItemArrayFromShellItem(psi: shellItem, riid: ref riid2, ppenum: out ppenum); UIObject source; using (var appLaunchWaiter = new AppLaunchWaiter(topLevelWindowCondition: topLevelWindowCondition)) { new ApplicationActivationManager().ActivateForProtocol(appUserModelId: appName, itemArray: ppenum, processId: out var _); appLaunchWaiter.Wait(); source = appLaunchWaiter.Source; } return(GetTopLevelUIObject(topWindow: source)); }