[UWP] [XAML]启动应用“app1”另一个应用程序“app2”如果“app1”没有开始 [英] [UWP][XAML] start an app "app1" by another app "app2" if "app1" is not start

查看:114
本文介绍了[UWP] [XAML]启动应用“app1”另一个应用程序“app2”如果“app1”没有开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好


我有2个应用,例如"app1"和"app2"我需要通过app2启动app1,我做的是 


Launcher.LaunchUriAsync(new Uri(" test:"));并创建了一个协议。


现在我需要检查"app1"在启动之前是否已经处于启动模式。是否可以通过"app2"进行检查。 ?




sandeep chauhan

解决方案

你好,


欢迎来到开发通用Windows应用程序
论坛!


请阅读粘贴帖子,特别是  发布指南:主题行
标签
  Windows 10 SDK和工具的已知问题 ,
并且不要忘记在您的问题中添加标记。


您可以通过两种方式。 


首先为"app1"创建OutOfProcess appservice然后在"app1"上在本地设置中启动可以保存像"AppRunning"这样的值。在Suspended回调中保存"AppSuspended"并在appservice 返回此
值。在这种情况下,您无法确定应用已关闭或暂停。


第二您可以启用
设备门户
,然后请求所有活动进程。并在此列表中按''app1'搜索打包全名,如果你没找到则应用程序没有运行,如果你发现那么可以通过"IsRunning"确定它是否被暂停属性。

 

private async void Button_Click(object sender,RoutedEventArgs e)
{
HttpRequestMessage request = new HttpRequestMessage (HttpMethod.Get,new Uri(" https:// localhost:50443 / api / resourcemanager / processes"));
HttpBaseProtocolFilter httpBaseProtocolFilter = null;
try
{
httpBaseProtocolFilter = new HttpBaseProtocolFilter();
httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired);
httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.IncompleteChain);
httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName);
httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);

// DevicePortal凭证如果需要
httpBaseProtocolFilter.ServerCredential = new Windows.Security.Credentials.PasswordCredential(" https:/ / localhost:50443 /"," myUser"," myPassword");
HttpClient client = new HttpClient(httpBaseProtocolFilter);
var result = await client.SendRequestAsync(request);
var stringResuit = await result.Content.ReadAsStringAsync();
var processes = Newtonsoft.Json.JsonConvert.DeserializeObject< ProcessesContainer>(stringResuit);

}
catch(exception ex)
{

}
}


public class ProcessesContainer
{
public IEnumerable< Process>进程{get;组; }
}

公共类进程
{
public string AppName {get;组; }
public double CPUUsage {get;组; }
public string ImageName {get;组; }
public bool IsRunning {get;组; }
public string PackageFullName {get;组; }
public int PageFileUsage {get;组; }
public int PrivateWorkingSet {get;组; }
public string Publisher {get;组; }
public int SessionId {get;组; }
public int TotalCommit {get;组; }
公共字符串UserName {get;组; }
public long VirtualSize {get;组; }
public long WorkingSetSize {get;组; }
public AppVersion Version {get;组; }
}

公共类AppVersion
{
public string Major {get;组; }
public string Minor {get;组; }
public string Build {get;组; }
public string Revision {get;组; }
}
}



Hi

I have 2 apps like "app1" and "app2" I need to start app1 by app2 which I did by 

Launcher.LaunchUriAsync(new Uri("test:")); and created a protocol.

Now I need to check "app1" is already in start mode or not  before launching. Is it possible to check by "app2" ?


sandeep chauhan

解决方案

Hello,

Welcome to the Developing Universal Windows apps forum!

Please read the sticky posts, especially the Guide to posting: subject line tags and Known Issues for Windows 10 SDK and Tools , and don't forget add tag to your question.

You can go by the two ways. 

First is create OutOfProcess appservice for "app1" then on "app1" launch in local settings save value like "AppRunning" an in Suspended callback save "AppSuspended" and in appservice  return this value. In this case you can not determine is app closed or suspended.

Second you can enable device portal on Device and then request for all active process. and in this list search by ''app1" package full name and if you not found then app not running if you find then can determine is it suspended or not by "IsRunning" property.

private async void Button_Click(object sender, RoutedEventArgs e) { HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, new Uri("https://localhost:50443/api/resourcemanager/processes")); HttpBaseProtocolFilter httpBaseProtocolFilter = null; try { httpBaseProtocolFilter = new HttpBaseProtocolFilter(); httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired); httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.IncompleteChain); httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName); httpBaseProtocolFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted);

//DevicePortal credentals if needed httpBaseProtocolFilter.ServerCredential = new Windows.Security.Credentials.PasswordCredential("https://localhost:50443/", "myUser", "myPassword"); HttpClient client = new HttpClient(httpBaseProtocolFilter); var result = await client.SendRequestAsync(request); var stringResuit = await result.Content.ReadAsStringAsync(); var processes = Newtonsoft.Json.JsonConvert.DeserializeObject<ProcessesContainer>(stringResuit); } catch (Exception ex) { } } public class ProcessesContainer { public IEnumerable<Process> Processes { get; set; } } public class Process { public string AppName { get; set; } public double CPUUsage { get; set; } public string ImageName { get; set; } public bool IsRunning { get; set; } public string PackageFullName { get; set; } public int PageFileUsage { get; set; } public int PrivateWorkingSet { get; set; } public string Publisher { get; set; } public int SessionId { get; set; } public int TotalCommit { get; set; } public string UserName { get; set; } public long VirtualSize { get; set; } public long WorkingSetSize { get; set; } public AppVersion Version { get; set; } } public class AppVersion { public string Major { get; set; } public string Minor { get; set; } public string Build { get; set; } public string Revision { get; set; } } }


这篇关于[UWP] [XAML]启动应用“app1”另一个应用程序“app2”如果“app1”没有开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆