1

I have developed a windows 8 app which involves the Live tile being invoked through Background Task thus displaying certain RSS Feeds.

However, when i install the app and right click on the tile, the button app bar does not have the button to turn off/on live tiles, i.e. Live tiles do not work.

However in a day or 12 hours, Live tiles start getting automatically updated.

How can i Make the Live tiles Run immediately after the installation?(Keeping in mind that these are Rss feeds to be displayed).

My Code-

private async void RegisterBackgroundTask()
    {
        try
        {
            var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
            if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
            backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
            {
                foreach (var task in BackgroundTaskRegistration.AllTasks)
                {
                    if (task.Value.Name == taskName)
                    {
                        task.Value.Unregister(true);
                    }
                }

                BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
                taskBuilder.Name = taskName;
                taskBuilder.TaskEntryPoint = taskEntryPoint;
                taskBuilder.SetTrigger(new TimeTrigger(15, false));
                var registration = taskBuilder.Register();
            }
        }
        catch
        { }
     }
YashVj
  • 63
  • 10

2 Answers2

1

Assuming you have function UpdateTile() in the Run method of your IBackgroundTask that really does the tile updating, make a public method in the IBackgroundTask class calling that UpdateTile() method.

public sealed class TileUpdater : IBackgroundTask
{    
    public async void Run(IBackgroundTaskInstance taskInstance)
    {
        // Get a deferral, to prevent the task from closing prematurely 
        // while asynchronous code is still running.
        BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

        // Update the live tile with the names.
        UpdateTile(await GetText());

        // Inform the system that the task is finished.
        deferral.Complete();
    }
    public async static void RunTileUpdater()
    {
        UpdateTile(await GetText());
    }
}

Then call RunTileUpdater() in your App code after

var registration = taskBuilder.Register();
TileUpdater.RunTileUpdater(); // <<<<-----
Jussi Palo
  • 848
  • 9
  • 26
1

Your app must be started at least once for the background task to get registered. Once registered your background task will run every time after the interval specified elapses.

abhinav
  • 527
  • 3
  • 11
  • 24