예제 #1
0
        protected void Connection_Disconnect(Connection Sender, DisconnectMessage Message)
        {
            // On disconnect, make sure we're invoked on the UI thread
            if (!Dispatcher.CheckAccess())
                Dispatcher.Invoke((Action<Connection, DisconnectMessage>)Connection_Disconnect, Sender, Message);
            else
            {
                Connection.Disconnect -= Connection_Disconnect;

                // Close all windows unless they're the tray icon
                foreach (Window w in Windows)
                {
                    if (w != MainWindow)
                    {
                        if (!w.Dispatcher.CheckAccess())
                            w.Dispatcher.Invoke((Action)w.Close);
                        else
                            w.Close();
                    }
                }
                // Only hide the tray icon, not close
                MainWindow.Hide();

                // Show the disconnection message
                MessageBox.Show("Lost connection to the server. Will continue trying to connect in the background.");

                // Restart the connection task
                NetTask = Task.Factory.StartNew(NetHandler);
            }
        }
예제 #2
0
 // Close all windows if the server disconnects
 private void Connection_Disconnect(Connection Sender, NetCore.Messages.DisconnectMessage Message)
 {
     if (MainWindowShown)
     {
         MainWindow.Dispatcher.Invoke((Action)Close);
     }
     if (AdminWindowShown)
     {
         AdminWindow.Dispatcher.Invoke((Action)Close);
     }
 }
예제 #3
0
        protected void Client_Disconnect(Client Sender, DisconnectMessage Msg)
        {
            // Detach event handlers
            Sender.Disconnect -= Client_Disconnect;
            Sender.MessageReceived -= Client_MessageReceived;

            Sender.Dispose();

            lock (Clients) // Thread safe
                Clients.Remove(Sender);

            // Fire disconnection event
            ClientDisconnect(this, Sender, Msg);
        }
예제 #4
0
        // On the server disconnecting
        private static void Disconnected(Connection Sender, DisconnectMessage Message)
        {
            // Unhook handlers
            Server.MessageReceived -= MessageReceived;
            Server.Disconnect -= Disconnected;

            // Reset the signals
            InitialisedEvent.Dispose();
            InitialisedEvent = null;
            UserEvent.Dispose();
            UserEvent = null;
        }
예제 #5
0
 private void Connection_Disconnect(Connection Sender, DisconnectMessage Message)
 {
     // If the server disconnects, close the window
     Dispatcher.Invoke((Action)Close);
 }