有了SignalR的问题/缺乏知识,我有一个Hub客户端/服务器和一个单独的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但我仍然得到相同的行为。