3

In my Package.appxmanifest file, I added a declaration for Background Tasks," because I will eventually need one - it hasn't been written yet. I selected "System event" as the Supported task type, but nothing in the App settings (Executable, Entry point, Start page) yet.

When I try to run the app after adding that declaration, I get: "App manifest is missing required element '/Package/Applications/Application/Extensions/Extension/BackgroundTasks/Task'"

So is there some value I can enter into one of the "App settings" edit boxes, or do I have to first create the Background Task before I declare that I'm going to use one, or...???

UPDATE

According to http://www.silverlightshow.net/items/Windows-8-metro-make-your-app-alive-with-background-tasks.aspx, the ControlChannel option can be used for sockets:

"ControlChannel: these tasks, only available in XAML/C# applications, can be notified when a network resource receive some data. These are related mostly with StreamSockets. Also this task requires the lock screen constraint."

The article also mentions: "...you can be notified about a number of system events. These event are triggered when something happen, like an incoming SMS, ..." but if I understand correctly, only Mobile Service Providers can implement the SMSReceived event.

But one of the things I'm still not clear on is: Can I create a class within my project that will be the background task, or do I need to add a project to my solution that will be/include the Background task? If the latter, should this project be a "Class Library (Windows Store Apps)" or "Windows Runtime Component" project type?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862

3 Answers3

2

You can define background task in app manifest file. There is no such requirements on where the background task is defined, you can put you first page address. See image below. You need to define Task Type. In my case I defined Timer. Also the Entry point which in my case I defined ItemsPage.cs, (I don't have Background Task in ItemsPage.cs). enter image description here

After that you need to have Badge logo and Lock Screen Notifications in Application UI tab. enter image description here

Mayank
  • 8,777
  • 4
  • 35
  • 60
  • I'm guessing for my situation I probably need "System event" (assuming there is a system event for an incoming socket message). It seems that Entry point = seems too vague, though -isn't it necessary to declare the exact name of the .dll that will run? And then - what "shape" should that take? – B. Clay Shannon-B. Crow Raven Nov 02 '12 at 15:07
  • Yeah it needs to be `NameOfTheDll.NameOfTheUnit`, it'll be the same thing. Checkout following example. [Background Task Sample](http://code.msdn.microsoft.com/windowsapps/Background-Task-Sample-9209ade9) – Mayank Nov 02 '12 at 16:58
2

You can define background task before actually implementing it, just:

  • in the manifest add capability Background Tasks, check Timer and in the Entry point line add the full name of the class containing the Background Task code. In my case I got there:

Tasks.UpdateTask

  • select type of Lock screen notifications and select Badge logo. Note Badge logo must be 24x24 and use only white color or (semi)transparent background

Update, the background task must be defined in another project and must be of type "Windows Runtime Component". Beware, projects of this type have several limitations and basically you won't be able to reference in it any other non-Windows Runtime Component libraries.
http://msdn.microsoft.com/en-us/library/windows/apps/br230301.aspx

Martin Suchan
  • 10,600
  • 3
  • 36
  • 66
  • I hope there's another option besides Timer, because this task needs to always be running, listening for incoming messages (using sockets). – B. Clay Shannon-B. Crow Raven Nov 02 '12 at 15:01
  • There is no way, how to create Windows Store (Metro) app, that is "always running in background". You can either use Push Notifications, or background task running each 15 minutes to check for something, but not "always in background". – Martin Suchan Nov 02 '12 at 16:19
  • Then how could a socket app be created? You never know when a message is going to come in via a socket. I think you're probably wrong, and I certainly hope you are. – B. Clay Shannon-B. Crow Raven Nov 02 '12 at 18:00
  • From http://code.msdn.microsoft.com/windowsapps/Background-Task-Sample-9209ade9: A background task can run even when the app that registered the background task is suspended. ... •Creating a background task that is triggered by a system event. So the background task, in order to be ever-ready to respond to an event, must be like a big cat hiding in the brush, normally stock still but always ready to pounce. – B. Clay Shannon-B. Crow Raven Nov 02 '12 at 18:19
  • Also, here: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/JJ662741(v=win.10).aspx it says, "This topic shows how to maintain network connections when a Windows Store app is in the background." – B. Clay Shannon-B. Crow Raven Nov 03 '12 at 01:28
  • More and more, it seems that MessageWebSocket may end up being just what the doctor ordered. – B. Clay Shannon-B. Crow Raven Nov 03 '12 at 05:00
  • it seems that's not true for the type of Background task I'm going to use (ControlChannelTrigger, for sockets); I believe the background task lives in the same app. – B. Clay Shannon-B. Crow Raven Nov 09 '12 at 00:31
1

You must create at least the entry point to be able to list it in the app manifest.

gdc
  • 545
  • 12
  • 23