我有一个运行 windows 10 IOT 核心的 Raspberry Pi 3,上面运行着 backgroundapplication1(BGA1)。
我可以从 BGA1 启动另一个 backgroundapplication2(BGA2) 吗?并从 BGA1 终止 BGA2 ?
我有一个运行 windows 10 IOT 核心的 Raspberry Pi 3,上面运行着 backgroundapplication1(BGA1)。
我可以从 BGA1 启动另一个 backgroundapplication2(BGA2) 吗?并从 BGA1 终止 BGA2 ?
也许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 获取完整的包名称。