Ejemplo n.º 1
0
        /// <summary>
        /// Occurs when an unhandled exception is thrown.
        /// </summary>
        /// <param name="ex">The exception thrown.</param>
        /// <param name="fatal">Whether this is fatal exception or not.</param>
        private static void OnUnhandledException(Exception ex, bool fatal = false)
        {
            try
            {
                // Log it
                Logger.Log(ex);

                // If it's fatal error
                if (fatal)
                {
                    fCrashed = true;

                    bool close = false;

                    try
                    {
                        ServerShutdownEventArgs args = new ServerShutdownEventArgs(ex);
                        Service.InvokeServerShutdown(args);
                        close = args.Close;
                    }
                    catch { }

                    // Dispose the pump
                    Transport.Dispose();
                    fStopping = true;
                }
            }
            catch (Exception e)
            {
                // Something went wrong
                Logger.Log(e);
            }
        }
Ejemplo n.º 2
0
        internal static void InvokeServerShutdown(ServerShutdownEventArgs e)
        {
            // Notify all clients
            try
            {
                foreach (var client in Service.Clients)
                {
                    InvokeClientDisconnect(new ClientDisconnectEventArgs(client));
                }
            }
            catch (Exception ex)
            {
                Service.Logger.Log(ex);
            }

            // Invoke shutdown
            Stopped?.Invoke(e);
        }