// ------------------------------------------------------------------
// GPRS connection control
// ------------------------------------------------------------------
private const int SUCCESS = 0;
private const int ERROR_NOT_ENOUGH_MEMORY = 8;
private const int RASBASE = 600;
private const int ERROR_BUFFER_TOO_SMALL = RASBASE + 3;
private const int ERROR_INVALID_SIZE = RASBASE + 32;
private const int RAS_MaxPhoneNumber = 128;
private const int RAS_MaxDeviceName = 128;
private const int RAS_MaxDeviceType = 16;
private const int MAX_PATH = 260;
// --- RASCONN data structure definition (refer to ras.h) --
private const int RAS_MaxEntryName = 20;
private const int ERROR_INVALID_PORT_HANDLE = (RASBASE + 1);
private const int ERROR_INVALID_HANDLE = 6;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct RASCONN

...{
public int dwSize;
public IntPtr hrasconn;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
public string szEntryName;
}

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
struct RASCONNSTATUS

...{
public int dwSize;
public int rasconnstate;
public int dwError;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType + 1)]
public string szDeviceType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName + 1)]
public string szDeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPhoneNumber + 1)]
public string szPhoneNumber;
};
// --------------------------------------------

[DllImport(
"coredll.dll", SetLastError =
true, CharSet = CharSet.Auto)]
private static extern uint RasEnumConnections([In, Out] RASCONN[] rasconn, [In, Out]
ref int cb, [Out]
out int connections);

[DllImport(
"coredll.dll")]
public static extern uint RasHangUp(IntPtr pRasConn);
重點來了 //執行RasHangUp後要確認離線後再離開
使用這段就好了
CloseAllConnections()