locked
Background Tasks in C++

    Question

  • I'm looking for more info on writing a background task component with C++/CX. Should this be done using the WinRT template? Can you reference other custom WinRT components from a background task project? 
    Monday, December 5, 2011 7:08 AM

Answers

  • @sb123123

    You can use the Background Task Sample in C# as a template on how to setup your project. The Manifest Declarations would be the same in C++ as in the sample. There was an earlier thread you should review regarding the syntax in C++ to get it working.

     

    Regarding debugging, you would set the BP in the background task code in VS Express. Once it triggers (in task manager you will see the BackgroundTaskHost.EXE load) and your BP in VS will (should be) hit. I have it working in C++ at the moment just as it does in the C# sample.

     

    Thanks,

    David Lamb

    Friday, December 9, 2011 11:09 PM
    Moderator
  • One point that wasn't clear until I tried it is that for a C++ project in VS to use with the background task you should select the template project for a WinRT component. From the background task you can access other custom WinRT component that you have by adding references. I got it working after I added a reference to the background task into my main C++ metro app and adding the background declarations to the metro c++ app's manifest like in the whitepaper. Not sure if you must put the reference in the main app to the background task project?
    Sunday, December 11, 2011 11:40 PM

All replies

  • I also would like to hear how the APPX manifest should be setup for a C++ background task component?

    How can I attach to the component and debug when it is started?

    Thanks again

    Monday, December 5, 2011 11:55 PM
  • Hello sb123123,

    This thread was created in the Windows Developer Preview: General OS forum; the Microsoft Moderation team has moved the thread to the Building Metro style apps with C++ forum.

    Thanks,
    Marilyn
    Tuesday, December 6, 2011 9:01 PM
  • @sb123123

    You can use the Background Task Sample in C# as a template on how to setup your project. The Manifest Declarations would be the same in C++ as in the sample. There was an earlier thread you should review regarding the syntax in C++ to get it working.

     

    Regarding debugging, you would set the BP in the background task code in VS Express. Once it triggers (in task manager you will see the BackgroundTaskHost.EXE load) and your BP in VS will (should be) hit. I have it working in C++ at the moment just as it does in the C# sample.

     

    Thanks,

    David Lamb

    Friday, December 9, 2011 11:09 PM
    Moderator
  • One point that wasn't clear until I tried it is that for a C++ project in VS to use with the background task you should select the template project for a WinRT component. From the background task you can access other custom WinRT component that you have by adding references. I got it working after I added a reference to the background task into my main C++ metro app and adding the background declarations to the metro c++ app's manifest like in the whitepaper. Not sure if you must put the reference in the main app to the background task project?
    Sunday, December 11, 2011 11:40 PM
  • That is correct. In your Metro App project, you would also create a reference  to the WinRT component (project).

     

    Tuesday, December 13, 2011 1:52 AM
    Moderator