我正在使用 SignalR.client DLL 与使用 SignalR 的网站进行对话。当客户端和站点在同一台机器上时,它可以完美运行。(立即调用 hub 方法)
但是,现在我通过网络在一台机器上设置了站点,调用(调用)平均需要 2.5 秒。(但工作)
我在 <1 毫秒内 ping 机器。
使用 Wireshark 我看到数据包在 2.5 秒后发送。
我调试了 SignalR.client dll,它卡在 System.Threading.Task 级别(在此处调用,在 HttpHelper.cs 中)
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Exceptions are flowed back to the caller.")]
    public static Task<Stream> GetHttpRequestStreamAsync(this HttpWebRequest request)
    {
        try
        {
            return Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream, request.EndGetRequestStream, null);
        }
        catch (Exception ex)
        {
            return TaskAsyncHelper.FromError<Stream>(ex);
        }
    }
知道什么会减慢这个过程吗?
非常感谢。
ps:我使用了 SignalR 聊天示例来重现延迟。
pps:这是我的测试应用程序的(非常简单的)代码:
var connection = new HubConnection("http://IP:PORT/SITENAME/");
    var myHub = connection.CreateHubProxy("ChatHub");
    // Start the connection
    connection.Start().Wait();
    while (true)
    {
      string sMsg = string.Format("Hello world from winform! Sent(winform) at {0}", DateTime.Now.ToString("hh:mm:ss.fff"));
      Console.WriteLine("Sending data : " + sMsg);
      myHub.Invoke("Send", "Winform", sMsg).ContinueWith(task2 =>
      {
        if (task2.IsFaulted)
        {
          Console.WriteLine("An error occurred during the method call {0}", task2.Exception.GetBaseException());
        }
        else
        {
          Console.WriteLine("Successfully called MethodOnServer at {0}", DateTime.Now.ToString("hh:mm:ss.fff"));
        }
      });
      Thread.Sleep(60*1000);
    }