connection hangup causes application to hang

Feb 10, 2011 at 5:41 PM

Hello,

When the app exits I need to disconnect the VPN.  If I start the VPN manually, then execute this function through the immediate window it will disconnect the VPN entry.  When this function is called as my app is exiting, the app "hangs" on calling hangUp().   Anyone have a suggestion why this could be happening?   I've spent several hours trying to figure this out so though might check here.

public static bool VPNDisconnect()
        {
            DotRas.RasDialer Dialer = new RasDialer();
            Dialer.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.User);
            RasConnection connection = RasConnection.GetActiveConnectionByName("myvpn", Dialer.PhoneBookPath);
           
                if (connection != null)
                {
                    try
                    {
                        connection.HangUp();
                        return true;
                    }
                    catch (Exception ex)
                    {
                        Utilities.writeLog("DisconnectVPN HangUp Exception: " + ex.ToString());
                        return false;
                    }
                }
                 return true;
        }

Feb 10, 2011 at 7:38 PM

I'm all set, it was my disconnect event handler firing and I was doing something to connect in there.  <embarrassed>