Monitor Wifi Connection Notifications

May 13, 2010 at 8:31 AM
Jeff, I see that you are using the ConnectionWatcher to monitor connections. How do you go about in your code to be constantly aware of notifications sent about the connection? I am asking because we need to monitor Wifi connections aswell and we need to monitor the status of the wifi connection. What my colleage is doing is to start a thread and then he has got an infinite loop (while) running to monitor for notifications and then send it back. The big drawback from this is that the while causes the processor usage to jump upto 50% which is unacceptable! Any idea on how I can maybe use your code to do the same thing? Thanks!
May 13, 2010 at 1:46 PM
Edited May 13, 2010 at 1:49 PM

If you're wanting the component to monitor all connection changes you just need to create an instance of the RasConnectionWatcher class and set the EnableRaisingEvents property to true. You can then wire up the event you're looking to get notifications from to begin receiving state change information. The threading is all being maintained within the component, so you don't need to do anything. However, you will need to set the SynchronizingObject property on the component if you want it to be able to update a user interface on the background thread that raises the events.

If you're curious how it all works, you're welcome to go browse or download the source code. That particular class is located in Trunk\Source\DotRas\DotRas\RasConnectionWatcher.cs.

If you have any other questions, feel free to ask. :)

Edit: If you're referring to the connection state of the Wifi network card, that isn't handled by the project. The RasConnectionNotification API only allows notification of RAS connections, which is what the component uses internally to prevent an infinite loop being required. It just receives notifications from Windows as the state of connections change.