Disconnect Mobile Broadband connection not working (C++/WinRT)
I have previously used the Mobile Broadband API but recent MSDN notes suggest developers should start using the WinRT equivalent API.
Starting in Windows 10, version 1803 (10.0; Build 17134), the Win32 APIs described in this section are superseded by the Windows Runtime APIs in the Windows.Networking.Connectivity namespace.
I can successfully create a mobile broadband connection with WinRT, but have not been able to get disconnect to work.
The porting guide mobile-broadband-networks-api-porting shows that to disconnect simply call ConnectionSession.Close(), but this does not seem to do anything. I am testing on Windows 10 21H2 if that makes any difference. My sample code is as follows:
#include <winrt/base.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Networking.Connectivity.h>
using namespace winrt;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Networking::Connectivity;
int main()
{
winrt::init_apartment();
CellularApnContext apn_context;
apn_context.AccessPointName(L"everywhere");
apn_context.UserName(L"eesecure");
apn_context.Password(L"secure");
apn_context.AuthenticationType(CellularApnAuthenticationType::None);
apn_context.IsCompressionEnabled(false);
auto call = ConnectivityManager::AcquireConnectionAsync(apn_context);
std::cout << "Connecting..." << std::endl;
call.get();
if (call.Status() == AsyncStatus::Completed)
{
ConnectionSession session = call.GetResults();
std::cout << "Connected!" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
std::cout << "Disconnecting..." << std::endl;
session.Close(); // <---- This should drop the connection!
std::cout << "Disconnected" << std::endl;
}
}
Also, why does the connection task take 30 seconds to complete when the device can connect and assign an IP in less than 5 seconds?