1

I am making an alerting application in Windows 10 using XAML and C#. I am using WNS to do my push notification. I have written a function that is triggered when I receive a notification within the app. Here is my code:

 private async void Channel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
    {
        e.Cancel = true;
        string jsonPayload = "{\"user_id\":\"" + CommonVariables.AuthenticateUserResponseDetails.user.id + "\"}";
        HttpClient client = new HttpClient();
        string postUrl = CommonVariables.SERVER + CommonVariables.Get_Alert;
        HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, postUrl);
        //encrypt tase

        EDecrypt encrypt = new EDecrypt();
        jsonPayload = encrypt.AES_Encrypt(jsonPayload, CommonVariables.EncryptionKey);

        request.Content = new StreamContent(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(jsonPayload)));
        var result = await client.SendAsync(request);
        string response = string.Empty;
        response = await result.Content.ReadAsStringAsync();
        EDecrypt edecrypt = new EDecrypt();
        response = edecrypt.AES_Decrypt(response, CommonVariables.EncryptionKey);
        response = response.Replace("\"", "");
        await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
        {
            messageBox(CommonVariables.AuthenticateUserResponseDetails.user.name +  " Please attend " + response + " Theatre");

        });

        ConfirmSeen();

    }

When I receive a notification however the message box appears twice. I have tried putting the message box code outside the Dispatcher but the app errors. What have I done wrong?

0 Answers0