Hello @21939029 ,
Welcome to Microsoft Q&A!
You can use Event NetworkInformation.NetworkStatusChanged.
public MainWindow()
{
this.InitializeComponent();
NetworkInformation.NetworkStatusChanged += NetworkStatusChanged;
}
private void NetworkStatusChanged(object sender)
{
Debug.WriteLine("NetworkStatusChanged");
}
I remember that your project is Winui3 C++, the following information is for your reference.
1.INetworkEvents::NetworkConnectivityChanged
The NetworkConnectivityChanged
method is called when network connectivity related changes occur.
2.Receiving Event Notifications Through WMI
Thank you.
Junjie
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
No, you can use it in WinUI3 desktop CPP app, it a WinRT API.
I was not able to find any documentation for its usage in CPP, can you please help me with an example for NetworkInformation.NetworkStatusChanged in CPP
A small tip, you can switch the C++/winrt version in the document.
What qualifies as a connection state change event? this document details when this event occurs.
NetworkStatusChangedEventHandler says it has one parameter which is IInspectable object.
i tried
But it gave this error
I was able to do it in C++ in like this
Sign in to comment