Skip to content

Commit

Permalink
Add waiting for VPN disconnected.
Browse files Browse the repository at this point in the history
  • Loading branch information
rinrab committed Jan 21, 2024
1 parent faee33b commit 88938b4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions AOVpnManager/RasApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace AOVpnManager
{
Expand Down Expand Up @@ -32,14 +33,24 @@ public static void DisconnectAll(Predicate<string> filter)
count = (cb + dwSize - 1) / dwSize;
}

bool wait = false;

for (int i = 0; i < count; i++)
{
if (filter(connections[i].szEntryName))
{
Trace.WriteLine("Disconnecting VPN connection '{0}'...");
RasHangUp(connections[i].hrasconn);
wait = true;
}
}

if (wait)
{
// Wait for disconnect. See: https://learn.microsoft.com/en-us/windows/win32/api/ras/nf-ras-rashangupa#remarks
// TODO: wait until RasGetConnectStatus() returns disconnected
Thread.Sleep(3000);
}
}

const int RAS_MaxEntryName = 256;
Expand Down

0 comments on commit 88938b4

Please sign in to comment.