2

我在使用 PushSharp 时发现了一个问题,希望你能给我一些启发。我在控制台 C# 应用程序中使用它一段时间(真)等待获取新的推送通知以发送,每次我在后端收到新通知时,我都会发送一批。

我实际上是在谈论两个问题:

1.如果我使用这种方式,在设备收到一些通知(有时是一个,两个或三个)后,它会突然停止接收新的通知。我注意到这个通知是在不同的日子发送的,我不是说一个接着一个。

例 1。

    public static PushBroker pushBroker;
    public static List<PushNotificationEnt> notificationsQueuedToBeSent = new List<PushNotificationEnt>();
    public static byte[] appleCert = File.ReadAllBytes(System.Configuration.ConfigurationSettings.AppSettings["certificate_path"]);


    static void Main(string[] args)
    {
        pushBroker = new PushBroker();
        pushBroker.OnNotificationSent += NotificationSent;
        pushBroker.RegisterAppleService(new ApplePushChannelSettings(bool.Parse(System.Configuration.ConfigurationSettings.AppSettings["isProduction"]), appleCert, "xxxxxxxxxxx"));



        DateTime timeController = DateTime.Now;
        int iteratorIdleController = 0;
        int cycleSeconds = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["cycle_seconds"]);


        while (true)
        {
            try
            {
                iteratorIdleController++;
                if ((DateTime.Now - timeController).TotalSeconds >= cycleSeconds)
                {
                    Console.Out.WriteLine("Starting iteration");
                    timeController = DateTime.Now;
                    SendPushNotifications();
                }
            }
            catch (Exception excp)
            {
                Console.Out.WriteLine("Error- " + excp.Message);
            }
        }
    }       

2. 如果我在每次循环开始时创建一个新的 PushBroker,控制台应用程序就会开始泄漏 RAM 内存,直到结束。

例 2。

    public static PushBroker pushBroker;
    public static List<PushNotificationEnt> notificationsQueuedToBeSent = new List<PushNotificationEnt>();
    public static byte[] appleCert = File.ReadAllBytes(System.Configuration.ConfigurationSettings.AppSettings["certificate_path"]);


    static void Main(string[] args)
    {
        DateTime timeController = DateTime.Now;
        int iteratorIdleController = 0;
        int cycleSeconds = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["cycle_seconds"]);


        while (true)
        {
            try
            {
                pushBroker = new PushBroker();
                pushBroker.OnNotificationSent += NotificationSent;
                pushBroker.RegisterAppleService(new ApplePushChannelSettings(bool.Parse(System.Configuration.ConfigurationSettings.AppSettings["isProduction"]), appleCert, "xxxxxx"));


                iteratorIdleController++;
                if ((DateTime.Now - timeController).TotalSeconds >= cycleSeconds)
                {
                    PushNotificationsSender pushNotificationsSender = new PushNotificationsSender(appleCert);

                    Console.Out.WriteLine("Starting iteration");
                    timeController = DateTime.Now;
                    SendPushNotifications();
                }
            }
            catch (Exception excp)
            {
                Console.Out.WriteLine("Error- " + excp.Message);
            }
        }
    }

我错过了什么吗?任何想法?

非常感谢!

4

0 回答 0