RasConnectionWatcher Class

DotRas SDK

Collapse image Expand Image Copy image CopyHover image
Listens to the remote access service (RAS) change notifications and raises events when connections change. This class cannot be inherited.

Namespace: DotRas
Assembly: DotRas (in DotRas.dll) Version: 1.3.5166.33435 (1.3.0.0)

Syntax

C#
public sealed class RasConnectionWatcher : RasComponent, 
	ISupportInitialize
Visual Basic
Public NotInheritable Class RasConnectionWatcher
	Inherits RasComponent
	Implements ISupportInitialize
Visual C++
public ref class RasConnectionWatcher sealed : public RasComponent, 
	ISupportInitialize
F#
[<SealedAttribute>]
type RasConnectionWatcher =  
    class
        inherit RasComponent
        interface ISupportInitialize
    end

Remarks

When using RasConnectionWatcher to monitor active connections for changes, ensure the SynchronizingObject property is set if thread synchronization is required. If this is not done, you may get cross-thread exceptions thrown from the component. This is typically needed with applications that have an interface; for example, Windows Forms or Windows Presentation Foundation (WPF).

The connected event raised by this component will be raised whenever a connection has connected on the machine. If a valid handle is provided to the Handle property, the other events will only receive notifications for that handle however the connected event will remain unchanged.

Examples

The following example shows how to use a RasConnectionWatcher object to monitor connection changes on a machine.
C# Copy imageCopy
RasConnectionWatcher watcher = new RasConnectionWatcher();  
public void Begin()
{
   watcher.Connected += new EventHandler<RasConnectionEventArgs>(this.watcher_Connected);
   watcher.Disconnected += new EventHandler<RasConnectionEventArgs>(this.watcher_Disconnected);
   watcher.EnableRaisingEvents = true;
}
private void watcher_Connected(object sender, RasConnectionEventArgs e)
{
   // A connection has successfully connected.
}
private void watcher_Disconnected(object sender, RasConnectionEventArgs)
{
   // A connection has disconnected successfully.
}
Visual Basic Copy imageCopy
Dim watcher As New RasConnectionWatcher
Public Sub Begin()
   AddHandler watcher.Connected, Me.watcher_Connected
   AddHandler watcher.Disconnected, Me.watcher_Disconnected
   watcher.EnableRaisingEvents = True
End Sub
Public Sub watcher_Connected(ByVal sender As Object, ByVal e As RasConnectionEventArgs)
   ' A connection has successfully connected.
End Sub
Public Sub watcher_Disconnected(ByVal sender As Object, ByVal e As RasConnectionEventArgs)
   ' A connection has disconnected successfully.
End Sub

Inheritance Hierarchy

See Also