This project is read-only.

Correct use of RasConnectionWatcher

Dec 19, 2011 at 11:30 PM

It may be only my inexperience, but I'm having some problems with the RasConnectionWatcher... and with the connection procedure in general.

Here are the relevant sections of my code

 

private static RasHandle handle = null;

...

private void Connect() {

...

handle = this.Dialer.DialAsync();

...

}

private void Dialer_DialComplete(object sender, DialCompletedEventArgs e)
{
   if (e.Connected)
   {
           this.rasConnectionWatcher.Handle = handle;
    }

}

 

private void Watcher_Disconnect(object sender, RasConnectionEventArgs e)
{
      Connect();
}

 

My problem is that when I first force disconnect the connection, the disconnect event comes in and the reconnection is processed. However I will not get the event after the second disconnection.

I'm also not able to disconnect based on the handle data .. the following code will hang the application.

 

RasConnection connection = RasConnection.GetActiveConnectionByHandle(handle);
if (connection != null)
{
   connection.HangUp();
}

 

My suspicion is that the second connection - after the disconnect event doesn't go through completely. The connection alive enough for data to pass through it and for RAS to see it as active (since launching the pbk will bring up the hang-up button and not the connect). But the connection is not live enough for connect to return with a good handle value... so when I try to either reconnect or disconnect with the broken handle value, the application locks up.

BTW: The synchronous dial does the same.

Has anyone run into this before?

 

Thanks

GL

Dec 20, 2011 at 6:38 AM

... Or please someone point me to a working RasConnectionWatcher example. I'm sorry to say that after several weeks, I'm still searching for one.

 

GL

Dec 21, 2011 at 1:35 AM

Sorry, my personal laptop died over the weekend so my ability to support the project has been extremely limited. Still not really sure what I'm going to do to fix that situation but I'll give what little help I can right now.

The only reason that HangUp would cause the call to hang indefinitely is the response from the API that is being called never returns a value other than indicating the connection is still connected. I've seen this in the past with others using the RasConnectionWatcher to immediately redial a connection after it has terminated. Why this behavior happens is a mystery to me, it's not something that DotRas has any control over. Suppose I could add a timeout to the method for 1.3, but that probably won't be getting released for quite a while.

My suggestion would be to use a timer that starts when the connection is disconnected and give it 5-10 seconds before attempting to reconnect. I'd check on the discussion forums here, I remember seeing similar problems from other users when using the RasConnectionWatcher to initiate re-dialing.

Jeff

Dec 21, 2011 at 9:00 AM

Thanks,

I had the same idea after running the project in debugger ... the problem went away, since the reconnection was not immediate. I implemented the timer and set it to 100ms. The app seems to be stable now.

1, Even though dotras is not to blame for this, please consider that it is not possible to disconnect such an immediately reconnected connection via dotras. However starting the pbk in explorer will properly show that the connection is active and will allow a disconnection 

2, Further tests show that when I force disconnect the connection (from the server side) the second time, even windows will not see that the connection had gone dead. The pbk will show it active ... so not getting a disconnect event is definitely an OS error ... but here the same applies as in point #1. Using the pbk I can click hang-up and the OS stabilizes. It also un-freezes the dotras based app.

To me this seems to indicate that error handling and recovery might further be improved.

Thanks

GL

Dec 21, 2011 at 2:27 PM

To your first point I may be able to do some testing around the scenario and see why HangUp isn't working when used in this situation. It may be that I just need to add another result value to look for that's being returned from the API. However that's a pretty big "if" in there, but I can at least attempt to replicate it sometime once I get a new computer and see what happens.

To your second point, it sounds like the problem may be related to the first. However, you also need to keep in mind that Windows may have access to pieces of RAS that they didn't expose within their API. Which means we're out of luck with making sure DotRas can safely handle these use cases you've presented.

If you can grab the source code and check what you're seeing in the DotRas.Internal.RasHelper HangUp method it would be a big help. I can't replicate every scenario easily due to the sheer number of variances between use cases, so most of these behavioral problems are fixed as the product lives. I'm hoping to have logging introduced in 1.3 so the source code isn't needed for this sort of problem.

Jeff