1

我正在使用 XAML 和 C# 在 Windows 10 中制作警报应用程序。我正在使用 WNS 进行推送通知。我编写了一个函数,当我在应用程序中收到通知时会触发该函数。这是我的代码:

 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();

    }

但是,当我收到通知时,消息框会出现两次。我尝试将消息框代码放在 Dispatcher 之外,但应用程序出错。我做错了什么?

4

0 回答 0