Signalr 信令客户端未重新连接

Signalr 信令客户端未重新连接,signalr,Signalr,由于对SignalR有问题/缺乏了解,我有一个集线器客户端/服务器和一个单独的GUI应用程序,它会间歇性地连接到集线器并发送消息。 我要么需要保持连接,要么在消息发送后断开连接 我遇到的问题是,它总是发送第一条消息,但在发送第二条消息时遇到了问题。我不确定这是为什么 public void SignalR_Connect(string message) { var connection = new HubConnection("http://site/signal

由于对SignalR有问题/缺乏了解,我有一个集线器客户端/服务器和一个单独的GUI应用程序,它会间歇性地连接到集线器并发送消息。 我要么需要保持连接,要么在消息发送后断开连接

我遇到的问题是,它总是发送第一条消息,但在发送第二条消息时遇到了问题。我不确定这是为什么

    public void SignalR_Connect(string message)
    {
        var connection = new HubConnection("http://site/signalr");
        IHubProxy myHub = connection.CreateProxy("chat");

        Console.WriteLine("Connection state is : " + connection.State.ToString());

            connection.Start().ContinueWith(task =>
            {
                Console.WriteLine("Attempting to Connect");
                if (task.IsFaulted)
                {
                    Console.WriteLine("There was an error opening the connection:{0}", task.Exception.GetBaseException());
                }
                else
                {

                    Console.WriteLine("Client Connected");
                }
            }).Wait();

           //Sending message
            myHub.Invoke("Send", message).ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Console.WriteLine("There was an error calling send: {0}", task.Exception.GetBaseException());
                    Console.WriteLine(task.Status.ToString());
                }
                else
                {
                    Console.WriteLine("Send Complete.");          
                }
            }).Wait();


        //Back round to get the next message.
        //Method grabs next message in the MSMQ and sends it to SignalR_Connect method.
        Read_Queue();
    }

我尝试了connection.stop(),在集线器上实现了一个close方法来通知服务器客户端离开,并设置了GlobalHost.Configuration.ConnectionTimeout,但我仍然得到了相同的行为

什么是
Read_Queue()?它在哪里发送第二条消息?为什么每次都重新连接?我确实有一个IF检查连接状态,但似乎没有影响。我如何保持连接并发送消息?啊,好的,如果我在开始时就连接,而不是每次都尝试断开/重新连接,效果会更好。