Perform a task on receiving a push notification in background in windows 8 RRS feed

  • Question

  • Hi

    i am working on a winrt app where i am generating some raw push notification from my azure mobile service. It is pushing every  minute raw notification. What I need is to handle these raw notification in the background so that I could perform some more tasks.

    sandeep chauhan

    Friday, October 25, 2013 7:28 AM

All replies

  • BackgroundTask with a PushNotificationTrigger see http://code.msdn.microsoft.com/windowsapps/Raw-notifications-sample-3bc28c5d/view/SourceCode#content

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, October 25, 2013 7:45 AM
  • Hi
    I have gone through the sample and implemented it in my app. Where I have designed the mobile service from where using the scheduler I am continuously pushing a raw notification to my app in every minute. To check wheather the background task run method is hitting or not. For this I have made the code to display a toast notification from there. But I think that it don't get hit any time until the default 15 minute span of background task.

    I am able to get the raw notification handled in the running and suspended state.
    But it is not working in the background state.

    What is happenning I can't figure it out. What it makes me to assume is that it don't initiate the run method to do a task before the 15 minute default span time.

    Am I correct pls help me out. And if it initiate then where am i doing the mistake.

    sandeep chauhan

    Friday, October 25, 2013 12:40 PM
  • you have a project you can share?

    and sending push notifications every minute is bad idea. i dont think this is supported

    can you explain your situation more in detail?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Friday, October 25, 2013 4:10 PM
  • Hi Dave

    Thanks for Contacting to us. I am more clarifying my situation here:-

    Yes I know that's not cool to push notifications every minute  mean while I am sharing my background task code. I have created the push channel from my main code in App.xaml.cs also.

    namespace ScheduledAgent
        public sealed class Test : IBackgroundTask
            BackgroundTaskDeferral _deferral;
            public static PushNotificationChannel CurrentChannel{ get; private set; }
            public async void Run(IBackgroundTaskInstance taskInstance)
                _deferral = taskInstance.GetDeferral();
                CurrentChannel =
                     await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
                CurrentChannel.PushNotificationReceived += OnPushNotification;
               // some code to work .............
                RawNotification notification = (RawNotification)taskInstance.TriggerDetails;
                Debug.WriteLine("Background  completed!");
            private async void OnPushNotification(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
                String notificationContent = String.Empty;
                switch (e.NotificationType)
                    case PushNotificationType.Raw:
                        notificationContent = e.RawNotification.Content;
                    //   some code to work......................
                e.Cancel = true;           

    The situation of my project is it contains certain reminders saved in the sqlite db. Where I need to show those reminders as toast notification when the app  is in background if they are set.

    The scenario is like this as we know background task do run in every 15 minute span. So there arrise's a condition where my certain reminders gets skipped as when the background task code runs certain reminders time period has elapsed and they don't fall into the conditions.

    Eg:- I create a task and set its reminder 5 minutes from the current time. This gets skipped.

    So what I am doing is I  have created a mobile service to push notifications. I have created a channel table where all channel uri will be saved. Then I  have created a scheduler which will push notifications to all channels every minute.

    There I need to initiate the background task when a raw notification is received.Run my code to find reminders in local db. So that no reminder gets lapsed.

    sandeep chauhan

    Monday, October 28, 2013 6:31 AM