/// <summary> /// Called if the form is closed /// </summary> /// <param name="sender">The sending object</param> /// <param name="e">The event arguments</param> private void MainForm_Closing(object sender, CancelEventArgs e) { //Disconnect/Logout if connected if (TdConnection != null) { if (TdConnection.Connected) { TdConnection.Disconnect(); } if (TdConnection.LoggedIn) { TdConnection.Logout(); } } }