c# - 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));
}
解决方案
推荐阅读
- android - Android - 仅为特定包名称获取小部件和小部件信息
- gremlin - gremlin 查询 - 如何使用 select in has
- swift - 为什么使用 URL 的 FileManager.default.enumerator 比 Swift 中的 String 快 3 倍?
- stripe-payments - 使用新的条带 api 键出现条带 \ PermissionException 错误
- java - 如何在 JTabbedPane 中添加文件菜单
- azure-active-directory - 如何使用 MS JAVA SDK for GRAPH API 重试请求?
- java - 如何使用带和不带冒号的 TimeZone 解析日期
- python - 使用 BeautifulSoup 抓取具有不变 URL 的多个页面
- flutter - 为什么 ListTile 在单击时不会默认闪现?
- android - TextInputLayout 侦听器不适用于更高版本的 API 28