Building on my previous articles (Windows 10 IoT Core: Starting a Package on Raspberry Pi  and Windows 10 IoT Core: Getting the MAC Address from Raspberry Pi) the following shows how to stop a running package.

We start with the function StopApp(), which can be called either of the following ways:

 

StopApp("PushButton", true);
StopApp("PushButton", false);

 

private async void StopApp(string appName, bool Force)
{
    String FullName = await GetPackageFullName(appName);
    byte toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(FullName);
    string appName64 = System.Convert.ToBase64String(toEncodeAsBytes);

    String URL = "http://localhost:8080/api/taskmanager/stop?" + (Force ? "?forcestop=true&" : "") + "package=" + appName64;

    System.Diagnostics.Debug.WriteLine(URL);

    StreamReader SR = await PostJsonStreamData(URL);
}

 

To stop the package we need the full name of the package, so let’s look it up by calling GetPackageFullName()

private async Task<String> GetPackageFullName(String PackageName)
{
    return await GetPackageNamedName(PackageName, "PackageFullName");
}

The code for GetPackageNamedName() can be found in Windows 10 IoT Core: Starting a Package on Raspberry Pi.

 

And now call PostJsonStreamData() which can also be found in Windows 10 IoT Core: Starting a Package on Raspberry Pi.

 

 

 

Copyright © 2015 – Bruce Eitman and Embedded101.com
All Rights Reserved