I'm working on a programm for RaspberryPi with Windows IoT core 17763. My IDE is Visual Studio 2019. I use C# and UWP for my programm.
Restart and shutdown doesn't work. For these functions the app has 3 buttons.
How does my app behave?
Here the relevant code of my application
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System;
using Windows.System;
public sealed partial class MainPage : Page
{
public MainPage()
{
InitializeComponent();
}
//button to exit application
private void FlyoutExit_Click(object sender, RoutedEventArgs e)
{
Application.Current.Exit();
}
//button to restart system
private void FlyoutReboot_Click(object sender, RoutedEventArgs e)
{
ShutdownManager.BeginShutdown(ShutdownKind.Restart, TimeSpan.FromSeconds(0));
}
//button to shutdown system
private void FlyoutShutdown_Click(object sender, RoutedEventArgs e)
{
ShutdownManager.BeginShutdown(ShutdownKind.Shutdown, TimeSpan.FromSeconds(0));
}
}
Here is the Package.appxmanifest
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10"
IgnorableNamespaces="uap mp iot">
<Capabilities>
<iot:Capability Name="systemManagement"/>
<Capability Name="internetClient" />
<iot:Capability Name="lowLevelDevices"/>
<DeviceCapability Name="serialcommunication">
<Device Id="any">
<Function Type="name:serialPort" />
</Device>
</DeviceCapability>
</Capabilities>
</Package>
When the application exits in debugging mode, visual studio will dis-connect the remote debugging. The behavior is correct. After the application exits, Windows IoT Core will start the default app which is configured as start-up.
ShutdownManager requires the use of the IoT systemManagement capability. You need to add the following to Package.appmanifest, otherwise, the app will exit with an exception.
<iot:Capability Name="systemManagement"/>