我试图通过进程内的AppService保持Win32 Console应用程序和UWP之间的交互。我认为我已经正确设置了所有内容,但是每次控制台应用程序尝试连接时,connection.OpenAsync()
产生的状态始终为“未知”。
PackageFamilyName
和AppServiceName
都是正确的,因为更改它们会导致预期的状态(AppNotInstalled
或AppServiceUnavailable
)。
我在做什么错?这是我在UWP应用的App.xaml.cs
中的代码:
public static AppServiceTriggerDetails appServiceDetails = null;
public static event EventHandler ConnectedToAppService;
protected override void OnBackgroundActivated(BackgroundActivatedEventArgs args)
{
base.OnBackgroundActivated(args);
if (args.TaskInstance.TriggerDetails is AppServiceTriggerDetails)
{
BackgroundTaskDeferral appServiceDeferral = args.TaskInstance.GetDeferral();
appServiceDetails = args.TaskInstance.TriggerDetails as AppServiceTriggerDetails;
ConnectedToAppService?.Invoke(null, null); //Never gets fired
}
}
这是控制台应用程序中的相关代码:
AppServiceConnection connection = new AppServiceConnection();
connection.RequestReceived += Connection_RequestReceived;
connection.ServiceClosed += Connection_ServiceClosed;
connection.AppServiceName = serviceName;
connection.PackageFamilyName = familyName;
var status = await connection.OpenAsync(); //This always returns "unknown"
Console.WriteLine("AppService connection status=" + status);