UWP / Win32之间的AppService始终具有“未知”连接状态

时间:2018-08-15 11:10:27

标签: c# uwp

我试图通过进程内的AppService保持Win32 Console应用程序和UWP之间的交互。我认为我已经正确设置了所有内容,但是每次控制台应用程序尝试连接时,connection.OpenAsync()产生的状态始终为“未知”。

PackageFamilyNameAppServiceName都是正确的,因为更改它们会导致预期的状态(AppNotInstalledAppServiceUnavailable)。

我在做什么错?这是我在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);

0 个答案:

没有答案