Reputation: 5023
I created a DialUp connection using the RASDIAL or RASPHONE exe. I want my application to monitor the established connection and if the connection gets disconnected my application should exit. How to manage this programatically? Please suggest me..
Upvotes: 1
Views: 2213
Reputation: 804
The correct Win32 API for receiving event based notifications regarding RAS connections and disconnections is RasConnectionNotification.
Here's a link: http://msdn.microsoft.com/en-us/library/aa376726(VS.85).aspx
If you're using the DotRas SDK on CodePlex the RasConnectionWatcher handles these notifications using the above mentioned API.
using DotRas;
RasConnectionWatcher watcher = new RasConnectionWatcher();
watcher.Connected += (sender, e) =>
{
// Connected!
};
watcher.Disconnected += (sender, e) =>
{
// Disconnected!
};
You can also specify a handle returned from RasDial to receive events specific to that handle by setting the Handle property.
watcher.Handle = handle;
watcher.EnableRaisingEvents = true;
Here's a link to DotRas if you're interested: http://dotras.codeplex.com
Edit: I just wanted to add, if you do not specify a handle to the either the DotRas or Win32 APIs, you'll receive events from all connects, disconnects, and bandwidth added/removed on the machine.
Upvotes: 1
Reputation: 175876
lpvNotifier
of the RadDial
function allows you to pass a RasDialFunc1
which will receive notification events regarding the lifetime of the connection. (RasGetConnectStatus
is also available for polling)
Upvotes: 0
Reputation: 1791
I suggest you use a thread to periodically check the status of the connection.
This can be done using RasEnumConnections from rasapi32.dll. This call returns the list of active connections, which you can then iterate over to check whether the one you opened is among them.
Upvotes: 2