In the rather helpful MSDN link here
, it says:
RAS supports referenced connections. If the entry being dialed is already connected, RasDial returns SUCCESS and the connection is referenced. To disconnect the connection, each RasDial on the connection should be matched by a RasHangUp.
Steps to reproduce:
This is done using the CreateAndDialVpnEntry WinForms example.
1) Dial the connection using Windows via Network Connections
2) Dial the same connection using the example application.
3) Press the Disconnect button.
At this point the application should hang since the connection has been dialed twice, thus making it a "referenced" connection.
The easy (and working) fix is that we add in the SafeNativeMethods.Instance.HangUp(handle); call inside of the loop to ensure all opened "reference" connections are closed.