[英]Can I launch a FullTrust Win32 app from within a UWP app's out-of-process background task?
I needed to read the registry every system login in order to determine whether to launch a notification or not.我需要在每次系统登录时读取注册表以确定是否启动通知。 So I had to create an out-of-process background task with SystemTriggerType.SessionConnected
to do this.因此,我必须使用SystemTriggerType.SessionConnected
创建一个进程外后台任务来执行此操作。 The background task implementation would look something like this:后台任务实现看起来像这样:
public async void Run(IBackgroundTaskInstance taskInstance)
{
Task launchFullTrust = LaunchFullTrustProcessForCurrentAppAsync(); //Windows.ApplicationModel.FullTrustProcessLauncher as an async task
launchFullTrust.Wait();
BackgroundTaskDeferral appServiceDeferral = taskInstance.GetDeferral();
AppServiceTriggerDetails details = taskInstance.TriggerDetails as AppServiceTriggerDetails;
Connection = details.AppServiceConnection; // AppServiceConnection object
...
// perform data acquisition
}
But because this background process is triggered by the session connectivity, it is guaranteed that taskInstance
will not contain AppServiceTriggerDetails
, or anything related to the AppServiceTrigger
at all.但是因为这个后台进程是由 session 连接触发的,所以可以保证taskInstance
不会包含AppServiceTriggerDetails
或任何与AppServiceTrigger
相关的内容。 Considering this, is there a way to receive a handle to the AppServiceConnection
connection from the background task, and not from the UWP app itself?考虑到这一点,有没有办法从后台任务而不是从 UWP 应用程序本身接收AppServiceConnection
连接的句柄?
To answer the main question if it is possible to launch a FullTrust Win32 app from an out-of-process background task: Yes要回答是否可以从进程外后台任务启动 FullTrust Win32 应用程序的主要问题:是
But the Win32 app will trigger the OnBackgroundTaskActivated
function of the Main UWP application.但是 Win32 应用程序将触发主 UWP 应用程序的OnBackgroundTaskActivated
function。 This means it would be better to continue from said function and obtain a handle to the AppServiceConnection
from there.这意味着最好从所述 function 继续并从那里获取AppServiceConnection
的句柄。 I was hoping to have a way to receive the connection on the background-task itself, but this situation seems workable for me.我希望有一种方法可以接收后台任务本身的连接,但这种情况对我来说似乎可行。 I am able to continue with this approach.我能够继续使用这种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.