启动另一个后台应用程序的后台应用程序
Background application that start another background application
我有一个 Raspberry Pi 3 运行 windows 10 IOT core with a backgroundapplication1(BGA1) 运行 on it.
我可以从 BGA1 启动另一个后台应用程序 2(BGA2) 吗?并从 BGA1 终止 BGA2 ?
不,你不能。 Background Applications:
launch at machine startup and run continuously without any process lifetime management resource use limitations
因此所有后台应用程序都在机器启动时启动。他们控制自己的生命周期(通过选择退出),但没有其他人可以直接关闭它。
也许 Windows IoT Core Device Portal REST API 有帮助。
以下是从另一个后台应用程序启动后台应用程序的简单代码示例:
namespace BackgroundApplicationStarter
{
public sealed class StartupTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
StartApp();
}
private async void StartApp()
{
string fullPackageNameEncoded = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("BackgroundApplication1234-uwp_1.0.0.0_arm__a48w6404kk2ea"));
Uri endpoint = new Uri("http://127.0.0.1:8080/api/iot/appx/app?appid=" + fullPackageNameEncoded);
var client = new System.Net.Http.HttpClient();
var byteArray = Encoding.ASCII.GetBytes("[insert your user name]:[insert your user password]");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("basic", Convert.ToBase64String(byteArray));
HttpContent content = new StringContent("", Encoding.UTF8);
System.Net.Http.HttpResponseMessage response = await client.PostAsync(endpoint, content);
HttpContent responseContent = response.Content;
Debug.WriteLine("Response StatusCode: " + (int)response.StatusCode);
}
}
}
完成部署后,您可以从 Device Portal 或 Visual Studio 获取完整的程序包名称。
我有一个 Raspberry Pi 3 运行 windows 10 IOT core with a backgroundapplication1(BGA1) 运行 on it.
我可以从 BGA1 启动另一个后台应用程序 2(BGA2) 吗?并从 BGA1 终止 BGA2 ?
不,你不能。 Background Applications:
launch at machine startup and run continuously without any process lifetime management resource use limitations
因此所有后台应用程序都在机器启动时启动。他们控制自己的生命周期(通过选择退出),但没有其他人可以直接关闭它。
也许 Windows IoT Core Device Portal REST API 有帮助。
以下是从另一个后台应用程序启动后台应用程序的简单代码示例:
namespace BackgroundApplicationStarter
{
public sealed class StartupTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
StartApp();
}
private async void StartApp()
{
string fullPackageNameEncoded = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("BackgroundApplication1234-uwp_1.0.0.0_arm__a48w6404kk2ea"));
Uri endpoint = new Uri("http://127.0.0.1:8080/api/iot/appx/app?appid=" + fullPackageNameEncoded);
var client = new System.Net.Http.HttpClient();
var byteArray = Encoding.ASCII.GetBytes("[insert your user name]:[insert your user password]");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("basic", Convert.ToBase64String(byteArray));
HttpContent content = new StringContent("", Encoding.UTF8);
System.Net.Http.HttpResponseMessage response = await client.PostAsync(endpoint, content);
HttpContent responseContent = response.Content;
Debug.WriteLine("Response StatusCode: " + (int)response.StatusCode);
}
}
}
完成部署后,您可以从 Device Portal 或 Visual Studio 获取完整的程序包名称。