SignalR 2启动故障

时间:2015-03-24 20:38:28

标签: signalr owin katana

尝试启动简单的Windows窗体SignalR服务器,但是当我进入WebApp.Start(URL)调试时,只是没有错误并且服务器无法正常工作。

如何调试signalR以及服务器无法正常工作的原因?

CODE:

using Microsoft.Owin.Hosting;
using Microsoft.AspNet.SignalR;

namespace MessengerServer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        const string URL = "http://localhost:8080";

        private void Form1_Load(object sender, EventArgs e)
        {
            WebApp.Start<Startup>(URL);
            richTextBox1.AppendText("Server running on " + URL);            
        }
    }

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR();
        }
    }

    public class MyHub : Hub
    {
        public void Send(string message)
        {
            Clients.All.addMessage(message);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

试试这个

private IDisposable SignalR { get; set; }
const string URL= "http://localhost:8080";

private void Form1_Load(object sender, EventArgs e)
{

   Task.Run(() => StartServer());
}

private void StartServer()
{
     try
     {
        SignalR = WebApp.Start(URL);
     }
     catch (TargetInvocationException)
     {

      }
      this.Invoke((Action)(() => richTextBox1.AppendText("Server running on " + URL)));

}