title: Disconnect clients on server exit
body: <p>Here's the server code I am using:</p>
  
  <pre><code>using System;
  using Microsoft.AspNet.SignalR;
  using Microsoft.AspNet.SignalR.Hubs;
  using Microsoft.Owin.Hosting;
  using Owin;
  using Microsoft.Owin.Cors;
  using System.Collections.Generic;
  
  
  namespace flar3server
  {
      class Program
      {
          static void Main(string[] args)
          {
              string url = "http://localhost:8080/";
              using (WebApp.Start(url))
              {
                  Console.WriteLine("Server running on {0}", url);
                  Console.ReadLine();
              }
          }
  
          [HubName("flar3hub")]
          public class flare3hub : Hub
          {
              static Dictionary&lt;string, ChatConnection&gt; connections = new Dictionary&lt;string, ChatConnection&gt;();
              Dictionary&lt;string, string&gt; registeredUsers = new Dictionary&lt;string, string&gt;()
              {
                  { "test1", "pass1" },
                  { "test2", "pass2" },
              };
  
              /*
              public string Send(string message)
              {
                  return message;
              }
               */
  
              public void Authenticate(string login, string password)
              {
                  Console.WriteLine("Login [" + Context.ConnectionId + "] " + login + ":" + password);
                  foreach (ChatConnection connection in connections.Values)
                  {
                      if (connection.getLogin() == login)
                      {
                          Clients.Caller.Action("ERROR: User already logged in.");
                          return;
                      }
                  }
                  if (!registeredUsers.ContainsKey(login) || registeredUsers[login] != password)
                  {
                      Clients.Caller.Action("ERROR: Login attempt failed.");
                      return;
                  }
                  connections[Context.ConnectionId] = new ChatConnection(login);
                  Clients.Caller.Action("Logged in successfully");
                  Clients.All.Action(login + " joined the channel.");
  
              }
  
              public void Broadcast(string message)
              {
                  try
                  {
                      Clients.All.sendMessage(connections[Context.ConnectionId].getLogin(), message);
                  }
                  catch (KeyNotFoundException)
                  {
                      Console.WriteLine("Unpaired [" + Context.ConnectionId + "] " + message);
                  }
              }
          }
      }
  }
  
  </code></pre>
  
  <p>And here's the client code:</p>
  
  <pre><code>using System;
  using Microsoft.AspNet.SignalR;
  using Microsoft.AspNet.SignalR.Hubs;
  using Microsoft.AspNet.SignalR.Client;
  
  namespace flar3client_cli
  {
      internal class flar3client_cli
      {
          private static void onDisconnected()
          {
              Console.WriteLine("Remote server closed the connection. Press enter to close the application.");
              Console.ReadLine();
              System.Environment.Exit(1);
          }
  
          private static void Main(string[] args)
          {
              //Set connection
              var connection = new HubConnection("http://localhost:8080/");
              //Make proxy to hub based on hub name on server
              var myHub = connection.CreateHubProxy("flar3hub");
              //Start connection
  
              connection.Start().ContinueWith(task =&gt;
              {
                  if (task.IsFaulted)
                  {
                      Console.WriteLine("There was an error opening the connection:{0}",
                                        task.Exception.GetBaseException());
                      Console.WriteLine("Press enter to continue...");
                      Console.ReadLine();
                      connection.Stop();
                      System.Environment.Exit(1);
                  }
                  else
                  {
                      Console.WriteLine("Connected");
                  }
  
              }).Wait();
              connection.Closed += onDisconnected;
  
  
              myHub.On&lt;string&gt;("Action", param =&gt;
              {
                  Console.WriteLine(param);
              });
  
              myHub.On&lt;string&gt;("SendMessage", param =&gt;
              {
                  Console.WriteLine(param);
              });
  
              myHub.Invoke&lt;string&gt;("Authenticate", "test1", "pass1").Wait();
  
  
              while (true)
              {
                  myHub.Invoke&lt;string&gt;("Broadcast", Console.ReadLine()).Wait();
              }
  </code></pre>
  
  <p>How can I make the server disconnect all clients when its application window is closed so that the clients can find that out?</p>