locked
C++ BackgroundTask

    Question

  • Hi all!

    I'm trying to write a simple Metro app with Background tasks in C++. I have the C# example and everything looks fine, but when I try to add the trigger for the taskbuilder, I get an IntelliSense error, that the IBackgroundTrigger is ambiguous. I don't know if this is still a bug in the WinRT, or I have done something wrong. Any help is appreciated.

    Code:

     

    BackgroundTaskBuilder^ myTaskBuilder = gcnew BackgroundTaskBuilder();
    myTaskBuilder->TaskEntryPoint = "Example::Process";
    myTaskBuilder->Name = "First";
    
    SystemTrigger^ myTrigger = gcnew SystemTrigger(SystemTriggerType::None, false);
    myTaskBuilder->setTrigger(myTrigger);  //ambiguous error on base class IBackgroundTrigger
    
    IBackgroundTaskRegistration^ myTask = myTaskBuilder->Register();
    

     


    • Edited by Forcecaster Saturday, September 17, 2011 5:30 PM
    Saturday, September 17, 2011 4:45 PM

Answers

  • I apologize for the late reply.  This does appear to be a bug.

    I was able to get the code to compile by changing the IBackgroundTrigger declaration to ISystemTrigger (which is actually inherited from IBackgroundTrigger).  This will get rid of the ambiguity error.

    ISystemTrigger ^myTrigger = ref new SystemTrigger(SystemTriggerType::None, false);
    myTaskBuilder->SetTrigger(myTrigger);
    


    • Marked as answer by Forcecaster Saturday, September 17, 2011 8:08 PM
    Saturday, September 17, 2011 8:02 PM

All replies

  • i think one of the problems is that you're using 'gcnew' instead of 'ref new' to create your objects.  gcnew is meant for instantiating .net types while ref new is used to create winrt types.
    Saturday, September 17, 2011 5:05 PM
  • Thanks for the answer, but even after changing the gcnew to ref new, the problem is still the same.
    Richard Forster
    Saturday, September 17, 2011 5:09 PM
  • a couple other things to do:

    use 'auto' (the C# example uses var) to declare types.  That will infer the correct type.

    also in the snippet 'setTriger' is misspelled.



    • Edited by A.Carter Saturday, September 17, 2011 5:31 PM
    Saturday, September 17, 2011 5:27 PM
  • Now I changed the declarations to auto, but it still not solved the problem. By the way I have edited the mispell in the original code.
    Richard Forster
    Saturday, September 17, 2011 5:31 PM
  • I apologize for the late reply.  This does appear to be a bug.

    I was able to get the code to compile by changing the IBackgroundTrigger declaration to ISystemTrigger (which is actually inherited from IBackgroundTrigger).  This will get rid of the ambiguity error.

    ISystemTrigger ^myTrigger = ref new SystemTrigger(SystemTriggerType::None, false);
    myTaskBuilder->SetTrigger(myTrigger);
    


    • Marked as answer by Forcecaster Saturday, September 17, 2011 8:08 PM
    Saturday, September 17, 2011 8:02 PM
  • Thank you for everyting! Now it's working.


    Richard Forster
    Saturday, September 17, 2011 8:08 PM