The complete StartupTask.cs program is shown here. In some of the earlier examples, we made some variables local, just to make it clear that they had to be of a particular type. In reality, we want those variables to be global. The final program reflects that, with LED_PIN, pin, pinValue, and timer declared as private global variables.

There are other code modules in the BlinkyHeadless project, but those are all automatically generated.  All we need concern ourselves with is the module StartupTask.cs:

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Net.Http;
 using Windows.ApplicationModel.Background;
 using Windows.System.Threading;
 using Windows.Devices.Gpio;
 // The Background Application template is documented at
 namespace BlinkyHeadless
     public sealed class StartupTask : IBackgroundTask
         BackgroundTaskDeferral _deferral;
         private const int LED_PIN = 5;
         private GpioPin pin;
         private GpioPinValue pinValue;
         private ThreadPoolTimer timer;
         public void Run(IBackgroundTaskInstance taskInstance)
             _deferral = taskInstance.GetDeferral();


             timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick,
         private void Timer_Tick(ThreadPoolTimer timer)
             if (GpioPinValue.High == pinValue)
                 pinValue = GpioPinValue.Low;
                 pinValue = GpioPinValue.High;
         private void InitGPIO()
             GpioController gpio = GpioController.GetDefault();
             pin = gpio.OpenPin(LED_PIN);
             pinValue = GpioPinValue.High;

This guide was first published on Aug 03, 2016. It was last updated on Aug 03, 2016.

This page (BlinkyHeadless Code) was last updated on Jul 14, 2016.

Text editor powered by tinymce.