I have a UWP app for Windows 10 setup to receive Raw and Toast notifications through WNS. I can correctly receive messages while in the foreground and while suspended in the background.
In the foreground, I setup a handler PushNotificaitonChannel.PushNotificationReceived and in the handler I set args.Cancel == true once I process the message.
For background processing I register an in-process background task using a PushNotificationTrigger(). This works great except for one perplexing issue: I often receive duplicate copies of the raw notifications. The number of duplicates can range from 1-20+.
I have seen this behavior on many different generations of Windows from build 14393 through the latest released build 17763.
I can reproduce the duplicates under visual studio and noticed that the call stacks vary between the first receipt and duplicate receipts. I haven't found any state hidden in the native/COM data structures that indicate how to stop the duplicates. I can post the stack traces if that would help.
I am hoping someone else knows how to stop this -- to somehow acknowledge the receipt of the raw WNS message in an in-process background task.
Many thanks for reading and pondering this issue.
EDIT: while working on the minimal example, I uncovered the following pattern of behavior.
- test app in foreground, send raw push; received normally
- close app via normal close button; app not running
- send new raw push; app starts in background and receives raw push fine; app goes to suspended state
- (app still suspended) send new raw push; app starts running; same raw push received TWICE; app goes back to suspended
- this can happen any number of times and the raw push is only ever received TWICE
- kill app (using End Task in Task Manager); app not running
- send new raw push; app starts running; same raw push received TWICE (as in #4); app goes back to suspended
- and the most odd of all: send new raw push and the app receives raw push THREE times; app goes back to suspended
- now, every raw push gets received THREE times; if I kill the app again and stat sending raw push, the number of dups goes up by one.