0

我已经使用此处描述的进程内机制开发了一个边缘浏览器扩展(本机消息传递)(通过激活OnBackgroundActivated)。在已建立的应用程序服务连接OnBackgroundActivated中,或者更具体地说OnAppServiceRequestReceived,我正在尝试调用Windows.System.Launcher.LaunchFileAsync(IStorageFile). 这似乎不会在 UI-Thread 上发生(尽管它确实在调试模式下工作并附加了调试器)。

我面临的问题是,应用程序是无头的,因此没有CoreWindow.GetForCurrentThread().Dispatcher,我也无法从Window.Current.

即使在发布模式或没有附加调试器的情况下,如何强制LaunchFileAsync在 UI-Thread 上执行?

我知道我可以简单地执行以下操作:

  await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, (async () =>
  {
    bool success = await Windows.System.Launcher.LaunchFileAsync(shortcut);
    await args.Request.SendResponseAsync(new ValueSet {
      { "message", "Launched File: " + success.ToString() }
    });
  }));

但我的问题是Dispatcher在 Application-Class 和OnAppServiceRequestReceived.

如何做到这一点?甚至有可能还是我需要一个完全信任的 Win32 桌面网桥?

即使使用

CoreDispatcher dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;

没有附加调试器就无法工作。我很好奇在没有 Win32 桌面桥的无头 UWP 应用程序中是否可以调用 LaunchFileAsync。

4

1 回答 1

0

You are correct - you will need to build a full-trust Win32 Desktop Bridge. The Dispatcher is not exposed inside the OnAppServiceRequestReceived context. So you wont be able to launch whatever you intend.

于 2018-06-14T06:49:06.280 回答