Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Latest commit

 

History

History

ForegroundAppWithBackgroundApp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
page_type urlFragment languages products description
sample
foregroundapp-backgroundapp
csharp
cpp
windows
windows-iot
An example of building a foreground app and background app within the same APPX file for Windows 10 IoT Core.

Foreground App with Background App

These are the available versions of this Windows 10 IoT Core sample.

In both versions, the Background App currently toggles a GPIO pin. If you are using a Dragonboard, you'll need to change LED_PIN in StartupTask.cpp (for C++) or StartupTask.cs (for C#) to a pin that exists on the Dragonboard (for example, the User LED 1: pin 21). You can find a list of available pins for the Dragonboard here.

About this sample

If you want to create a solution that builds the foreground application and the background application into the same .APPX file it will require manual steps to combine the two projects.

Steps

  1. File>New>Project…
  2. Create a new Blank App

step 2

  1. Select desired target version and click OK when prompted for target version

step 3

  1. In Solution Explorer right-click on the solution and choose Add>New Project …

step 4

  1. Create a new Background Application

step 5

  1. Select desired target version and click OK when prompted for target version

step 6

  1. In Solution Explorer right-click on the background application Package.appxmanifest and choose View Code

step 7

  1. In Solution Explorer right-click on the foreground application Package.appxmanifest and choose View Code

step 8

  1. At the top of the foreground Package.appxmanifest add xmlns:iot="http://schemas.microsoft.com/appx/manifest/iot/windows10" and modify IgnorableNamespaces to include iot.

    <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">
    
  2. Copy the from the Background Application project Package.appxmanifest to the Foreground Application Package.appxmanifest. It should look like this:

    <Applications>
    <Application Id="App"
        Executable="$targetnametoken$.exe"
        EntryPoint="MyForegroundApp.App">
        <uap:VisualElements
        DisplayName="MyForegroundApp"
        Square150x150Logo="Assets\Square150x150Logo.png"
        Square44x44Logo="Assets\Square44x44Logo.png"
        Description="MyForegroundApp"
        BackgroundColor="transparent">
        <uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
        <uap:SplashScreen Image="Assets\SplashScreen.png" />
        </uap:VisualElements>
        <Extensions>
        <Extension Category="windows.backgroundTasks" EntryPoint="MyBackgroundApplication.StartupTask">
            <BackgroundTasks>
            <iot:Task Type="startup" />
            </BackgroundTasks>
        </Extension>
        </Extensions>
    </Application>
    </Applications>
    
  3. In Solution Explorer right-click on the Foreground Application References node and choose Add Reference…

step 11

  1. Add a project reference to the Background Application   step 12

  2. In Solution Explorer right-click the foreground application project and choose Unload Project, then right-click the background application project and choose Unload Project.

step 13

  1. In Solution Explorer right-click on the foreground application project and choose Edit MyForegroundApp.csproj and then right-click on the background application project and choose Edit MyBackgroundApp.csproj.   step 14

  2. In the background project file comment the following lines:

    <!--<PackageCertificateKeyFile>MyBackgroundApplication_TemporaryKey.pfx</PackageCertificateKeyFile>-->
    <!--<AppxPackage>true</AppxPackage>-->
    <!--<ContainsStartupTask>true</ContainsStartupTask>-->
    
  3. In the foreground project file add true</ ContainsStartupTask> to the first PropertyGroup

    <PropertyGroup>
        <!-- snip -->
        <PackageCertificateKeyFile>MyForegroundApp_TemporaryKey.pfx</PackageCertificateKeyFile>
        <ContainsStartupTask>true</ContainsStartupTask>
    </PropertyGroup>
    
  4. In Solution Explorer right-click on each project and choose Reload Project

step 17

  1. In Solution Explorer delete Package.appxmanifest from the background application

step 18

  1. At this point the project should build (and run the implementation you have added to the foreground and background applications).