Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am self-hosting a SignalR server in a Windows forms application. It works well.

I need to change the KeepAlive, ConnectionTimeout, and DisconnectTimeout. I have placed the code to do this in various places within the server but none of those seem to change these items from the defaults. I have tried in program.cs, the constructor for the main form, and the OWIN startup class's Configuration method.

The examples I see all say to use Application_Start, but obviously that is for an ASP.NET application, not a Windows Forms one.

This is an example of that:

C#
protected void Application_Start(object sender, EventArgs e)
{
    // Make long polling connections wait a maximum of 110 seconds for a
    // response. When that time expires, trigger a timeout command and
    // make the client reconnect.
    GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);
    
    // Wait a maximum of 30 seconds after a transport connection is lost
    // before raising the Disconnected event to terminate the SignalR connection.
    GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(30);
    
    // For transports other than long polling, send a keepalive packet every
    // 10 seconds. 
    // This value must be no more than 1/3 of the DisconnectTimeout value.
    GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(10);
    
    RouteTable.Routes.MapHubs();
}


Does anyone have any ideas as to how to do something like this in a Windows Forms app?

Thanks!
Posted
Comments
SohaibX 15-Jul-15 12:31pm    
I think the right place for it is the OWIN class configuration..
I tested it few weeks ago. although right now even my default timeout (30 seconds) is not working on client connection lost.lol. So I cannot reconfirm it right now.
Do tell if you solve this Smile | :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900