Exemple #1
0
        protected virtual void CloseConnection()
        {
            if (StreamConnection != null)
            {
                Logger.LogDebug($"CloseConnection triggered {StreamConnection}");
                try
                {
                    {
                        StreamConnection.ConnectionShutdown -= OnConnectionShutdown;
                        if (StreamConnection.IsOpen)
                        {
                            StreamConnection.Close();
                            Logger.LogDebug("Connection Closed");
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.LogWarning($"Failed to close connection {e}");
                }

                try
                {
                    {
                        DisposeModel();
                        StreamConnection.Dispose();
                        Logger.LogDebug("Connection Disposed");
                    }
                }
                catch (Exception e)
                {
                    Logger.LogWarning($"Failed to dispose connection {e}");
                }
                StreamConnection = null;
            }
            else
            {
                Logger.LogDebug("No need to CloseConnection");
            }
        }