This project is read-only.

How to use RasConnectionWatcher to watch for initial connection?

Jun 9, 2010 at 9:29 PM

I built a quick little Winform app and I have it dumping info to a textbox to simply enumerate over the phonebook and then populate another textbox with the active connections... 

That's working perfect! I'm really liking what I see so far...

For the next step in my proof-of-concept test harness - I added a third textbox to show output from the RasConnectionWatcher events (Connected/Disconnected).  I enabled raising events and --- nothing happens...  I then dug in a little deeper and found the Handle property needed to be set.  What I was not able to figure out was how to set it initially so that I could catch the 1st connection...

What I do finally have working at this point is upon initially iterating over the active connections (RasDialer.GetActiveConnections), if I found an active connection, I could then use the Handle property from the RasConnection object to set the Handle on the RasConnectionWatcher.... With that, I could then see the Disconnect event and - surprisingly - any subsequent Connect events firing.

What I really need is to be able to tell the RasConnectionWatcher to watch for that very first initial connection -- which means I wouldn't have an RasConnection from calling GetActiveConnections() --  and from what I can tell there is no 'handle' for a given RasEntry at that point -- so the information provided to the watcher needs to be something that can be derived from the RasEntry somehow (i.e. the ID instead of a handle)... 

Any ideas? Or is this impossible with the current implementation?

Jun 9, 2010 at 9:42 PM
Edited Jun 9, 2010 at 9:45 PM

The connection event was supposed to fire with or without the handle being set, are you saying that it's not?

Edit: Try connecting the error event to monitor any exceptions that may be occuring on the background thread. Something could be happening in there causing the event to not fire as it should.

Jun 10, 2010 at 2:12 PM

I'll wire-up the other event handlers and see what is happening. But yes - my initial attempt was to just drop the control on the form, enable raising events, and then I took the event args info and simply dumped a message to a textbox from the Connected/Disconnected events....   nothing happened...   I'll re-test... 

Jun 10, 2010 at 2:24 PM

Hmmm.. Th RasConnectionMonitor doesn't expose an Error event...

I modified my test harness to not set the Handle property at first... rather I added a Button to do it...

            if (this.RasDialer.GetActiveConnections().Count > 0)
            {
                this.RasConnectionWatcher.Handle = this.RasDialer.GetActiveConnections()[0].Handle;
            }
            else
            {
                this.RasConnectionWatcher.Handle = null;
            }

I'm getting ready to build the test harness and deploy it to the device to see what I can get with the above...

Jun 10, 2010 at 2:45 PM

Well - today I see the Connected event firing after all.  The "modem" in use is actually a Sprint 3G (EVDO) device and I think their status screen/startup process was misleading me...

My next challenge will be to do this in a "provider" where there is no UI - the goal here is to make a new "Connection Type" provider for the Smart Client Software Factory's Network Connection Monitor - out of the box it is aware of wired and wireless network connections... not dial-up connections... which is how these Sprint devices appear...

Wish me luck... it should be as simple as connecting the dots I'm hoping...

Jun 10, 2010 at 3:15 PM

Glad to hear you got it working. If you have any other questions, feel free to ask.