C++ SystemTrigger Unhandled exception


  • In a previous question it have became clear, that we have bug in the C++ side of the WinRT and it looks like I have encounterd a new one.

    Now I don't have any compile error, the app starts up. If I have click on a button, the following snippet should kick in. Actually the thread doesn't seem to work, but if I have close the application, I have added the Console Subsystem for the project, and if I have close it trough the console, then I have an unhandled exception error (Windows.ApplicationModel.Background.SystemEventsBroker.dll, access violation reading location).

    But if I have commenting the two lines, which declares the Trigger, and then set it in the TaskBuilder I don't have this error. Of course, the task is dead, because the register do not get the parameters.

    Any ideas?


    BackgroundTaskBuilder^ myTaskBuilder = ref new BackgroundTaskBuilder();
    myTaskBuilder->TaskEntryPoint = "Example::Process";
    myTaskBuilder->Name = "First";
    ISystemTrigger^ myTrigger = ref new SystemTrigger(SystemTriggerType::None, false);
    IBackgroundTaskRegistration^ myTask = myTaskBuilder->Register();

    Richard Forster
    Saturday, September 17, 2011 10:34 PM


All replies

  • Hi,

    The None Trigger does not have any usage and will not do anything.

    Can you try this with a different trigger?


    Monday, September 19, 2011 6:56 PM
  • Thats strange, because now I got no errors at all. Even with the None Trigger it do not show any errors. The task still not working though.
    Richard Forster
    Monday, September 19, 2011 7:38 PM
  • Can you give details on the trigger that you are trying to use?

    How do you verify that your background task did not run?

    For a test , you can try the InternetAvailable trigger. By unplugging and plugging your network cable (or Wifi) you should see the trigger firing and the background task being executed.


    Tuesday, September 20, 2011 4:45 PM
  • I have changed the trigger to InternetAvailabe, run the app, and unplugged-plugged the cable. The task should have write a message to the console, but there's nothing.

    By the way, it looks like my original unhandled exception is still here if start up the app from VS in debug mode. If I start it without debugging, then no error.

    Here is my code:


    namespace GPU
    public ref class process:  IBackgroundTask
    	volatile bool _CancelRequested;
    	public: process()
    				_CancelRequested = false;
    	public: virtual void Run(IBackgroundTaskInstance^ taskInstance)
    	bool Canceled = false; 
                // If the cancellation handler indicated that the task was canceled, stop doing the task. 
                if (_CancelRequested) 
                    Canceled = true; 
    } // // Simulate doing work. // printf("Task run"); // // Indicate progress to foreground application. // taskInstance->Progress = 100; } }; } void GPU::MainPage::HelloButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { auto myTaskBuilder = ref new BackgroundTaskBuilder(); ISystemTrigger^ myTrigger = ref new SystemTrigger(SystemTriggerType::InternetAvailable, false); myTaskBuilder->SetTrigger(myTrigger); myTaskBuilder->TaskEntryPoint = "GPU::process"; myTaskBuilder->Name = "First"; auto myTask = myTaskBuilder->Register(); }

     In the manifest I have added the BackgroundTask, and checked System Event, Entry point: GPU.process.

    Richard Forster

    • Edited by Forcecaster Tuesday, September 20, 2011 6:17 PM
    Tuesday, September 20, 2011 5:00 PM
  • Hi,

    a printf is not going to work from a background task that runs in a different process.

    You need to associate a completion handler to your task so that your main application will be able to get the completion event of the background task. Note that this will only work if the application is still in the foreground.

    Try myTask.Completed and intellisense should help you here find the variable to set your completion handler.


    Thursday, September 22, 2011 7:11 AM
  • This is a white paper on background tasks titled "Introduction to Background tasks" which has more information on how to build background tasks. http://www.microsoft.com/download/en/details.aspx?id=27411

    This is a link to the background task sample in C# and JS which may be also be useful: http://code.msdn.microsoft.com/windowsapps/Background-Task-Sample-9209ade9


    Thursday, September 22, 2011 4:41 PM