PubNub上的StackOverflowException订阅

时间:2018-08-12 21:40:04

标签: c# pubnub

我正在尝试使用Nuget之外的PubnubPCL包进行订阅,但是,每当调用此函数时,程序都会在出现StackOverflow异常后约2秒退出。这是导致错误的完全相同的代码。我完全不知道为什么会这样,因为我在另一个程序中几乎使用完全相同的代码。这个功能似乎是引起StackOverflow异常的唯一原因。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PubnubApi;

namespace PubnubTest
{
    class Program
    {

        static void Main(string[] args)
        {
            Pubnub pubnub = new Pubnub(new PNConfiguration(){ SubscribeKey = "<removed>", ReconnectionPolicy = PNReconnectionPolicy.LINEAR });

            pubnub.AddListener(new SubscribeCallbackExt(
                (pubnubObj, message) => {
                    Console.WriteLine(message);
                },
                (pubnubObj, presence) => { Console.WriteLine(presence.ToString()); },
                (pubnubObj, status) => {
                    if (status.Category == PNStatusCategory.PNUnexpectedDisconnectCategory)
                    {
                        Console.WriteLine("[ERROR] Pubnub unexpectedly disconnected.");
                    }
                    else if (status.Category == PNStatusCategory.PNConnectedCategory)
                    {
                        Console.WriteLine("[LOG] Pubnub successfully connected.");
                    }
                    else if (status.Category == PNStatusCategory.PNReconnectedCategory)
                    {
                        Console.WriteLine("[LOG] Pubnub reconnecting...");
                    }
                    else if (status.Category == PNStatusCategory.PNDecryptionErrorCategory)
                    {
                        Console.WriteLine("[ERROR] Could not decrypt recieved message.");
                    }
                    else if (status.Category == PNStatusCategory.PNBadRequestCategory)
                    {
                        Console.WriteLine("[ERROR] An unexpected error occurred.");
                    }
                }
            ));

            pubnub.Subscribe<string>()
             .Channels(new string[] {
                 "<removed>"
             }).WithPresence()
             .Execute();

            Console.ReadLine();
        }
    }
}

0 个答案:

没有答案