locked
Windows Forms Server: Changing KeepAlive and Timeout settings? RRS feed

  • Question

  • User1421457573 posted

    I have been trying to change the KeepAlive and Timeout settings with SignalR being hosted in a Windows Forms application. The examples of where to do this show it for an ASP.NET application, using Application_Start.

    I have tried putting 

    GlobalHost.Configuration.KeepAlive = TimeSpan.FromSeconds(3);

    into program.cs, the main form's constructor, and the Configuration method within the OWIN startup class. None of these worked. I need to change the defaults for this because I need the clients and server to respond within 3 seconds if the connection fails, the server crashes,, a client crashes, or something else happens that causes a problem.

    Thanks!

    Wednesday, July 15, 2015 10:19 AM

Answers

  • User1644755831 posted

    Hello David,

    Please see this: http://stackoverflow.com/questions/27712784/signalr-self-host-disconnect-timeout-without-global-asax

    As suggested can you try the call to GlobalHost before startup is called. So try something like below.

    using System;
    using Microsoft.AspNet.SignalR;
    using Microsoft.Owin.Hosting;
    using Owin;
    using Microsoft.Owin.Cors;
    
    namespace SignalRSelfHost
    {
    class Program
    {
        static void Main(string[] args)
        {
            // This will *ONLY* bind to localhost, if you want to bind to all addresses
            // use http://*:8080 to bind to all addresses. 
            // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx 
            // for more information.
            string url = "http://localhost:8080";
            GlobalHost.Configuration.ConnectionTimeout  =   new TimeSpan(0, 0, 110);
            GlobalHost.Configuration.DisconnectTimeout  =   new TimeSpan(0, 0, 60);
            GlobalHost.Configuration.KeepAlive          =   new TimeSpan(0, 0, 5);
            using (WebApp.Start(url))
            {
                Console.WriteLine("Server running on {0}", url);
                Console.ReadLine();
            }
        }
    }
    class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.UseCors(CorsOptions.AllowAll);
            app.MapSignalR();
        }
    }
    public class MyHub : Hub
    {
        public void Send(string name, string message)
        {
            Clients.All.addMessage(name, message);
        }
    }
    } 

    Hope this helps.

    With Regards,

    Krunal Parekh

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 16, 2015 4:19 AM