This project is read-only.

RasConnectionState.Disconnected not triggered

Apr 13, 2010 at 9:41 AM

 

RasConnectionState.Disconnected not triggered
I can't seem to get RasConnectionState.Disconnected to trigger my event handler
private RasDialer dialer = new RasDialer();
dialer.StateChanged += new EventHandler<StateChangedEventArgs>(dialer_StateChanged);
Then event handled by:
void dialer_StateChanged(object sender, StateChangedEventArgs e)
            {
                // Handle state changes here
                switch (e.State)
                {
                    case RasConnectionState.Connected:
                        internetConnected = true;
                        Console.WriteLine(e.State.ToString());
                        break;
                    case RasConnectionState.Disconnected:
                        internetConnected = false;
                        Console.WriteLine(e.State.ToString());
                        break;
                    default:
                        Console.WriteLine("INFO -> Unhandled state: " + e.State.ToString());
                        break;
                }
            }
RasConnectionState.Disconnected not triggered, even when RasConnection.Hangup() is called...

 

I can't seem to get RasConnectionState.Disconnected to trigger my event handler

 

private RasDialer dialer = new RasDialer();


dialer.StateChanged += new EventHandler<StateChangedEventArgs>(dialer_StateChanged);

 

Then event handled by:

 

void dialer_StateChanged(object sender, StateChangedEventArgs e)

            {

                // Handle state changes here

                switch (e.State)

                {

                    case RasConnectionState.Connected:

                        internetConnected = true;

                        Console.WriteLine(e.State.ToString());

                        break;

                    case RasConnectionState.Disconnected:

                        internetConnected = false;

                        Console.WriteLine(e.State.ToString());

                        break;

                    default:

                        Console.WriteLine("INFO -> Unhandled state: " + e.State.ToString());

                        break;

                }

            }

RasConnectionState.Disconnected not triggered, even when RasConnection.Hangup() is called... What am I doing wrong?

 

 

Apr 13, 2010 at 9:50 AM

http://pastebin.blazeware.net/5

 

for complete code

Apr 13, 2010 at 3:29 PM

Ah, a very simple mistake. Basically the RasDialer component only handles events while a dialing operation is in progress. The disconnected event would be raised if perhaps the modem line became unplugged during the connection attempt. If you want to monitor client connections on the machine for connection/disconnection or a couple other events, use a RasConnectionWatcher. It will receive notifications from Windows when connection changes are made outside of a dialing operation.

Apr 14, 2010 at 1:10 AM

Ah... My bad... The Class name 'Ras[b]Dialer[/b]' should have been a hint I suppose....

Apr 14, 2010 at 1:26 AM

Lol, it happens to the best of us. Don't worry about it. If you have any other questions feel free to ask. :)

Apr 14, 2010 at 1:36 AM

Cheers Jeff. I have it working now. Thanks for the heads up :)