首页 > 解决方案 > appSerivce被系统杀死的情况如何解决?

问题描述

我的WinForm应用和uwp通过appService通信,在app.xaml.cs中实现appService功能,但是系统随时会kill appService,请问如何解决这个问题。这是 WinForm 中的代码:

var appService = new AppServiceConnection();

// Here, we use the app service name defined in the app service provider's Package.appxmanifest file in the <Extension> section.
appService.AppServiceName = AppServiceName; 

// Use Windows.ApplicationModel.Package.Current.Id.FamilyName within the app service provider to get this value.
appService.PackageFamilyName = PackageFamilyName; 

var status = await appService.OpenAsync();
if (status != AppServiceConnectionStatus.Success)
{
    textBox2.Text = "fail";
    return;
}

这是uwp中的代码:

protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args)
{
    base.OnBackgroundActivated(args);
    IBackgroundTaskInstance taskInstance = args.TaskInstance;
    AppServiceTriggerDetails appService = taskInstance.TriggerDetails as AppServiceTriggerDetails;
    appServiceDeferral = taskInstance.GetDeferral();
    taskInstance.Canceled += OnAppServicesCanceled;
    appServiceConnection = appService.AppServiceConnection;
    appServiceConnection.RequestReceived += OnAppServiceRequestReceived;
    appServiceConnection.ServiceClosed += AppServiceConnection_ServiceClosed;


    //timer = ThreadPoolTimer.CreatePeriodicTimer((t) => {
    //    callCount++;
    //}, TimeSpan.FromMilliseconds(200));

}

标签: c#winformsuwp

解决方案


推荐阅读