我的WinForm应用程序和uwp通过appService进行通信并在app.xaml.cs中实现appService功能,但系统会随时终止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));
}