Sub Main(ByVal args As String())
' Open a connection to the Oracle server.
Dim con As New OracleConnection("Server = ora; User Id = sys; Password = pwd; Mode = SysDba")
con.Open()
' Create the OracleAlerter instance and register it for the "my_alert" Oracle Alert.
Dim alerter As New OracleAlerter
alerter.Connection = con
alerter.AlertName = "my_alert"
alerter.Timeout = 5
alerter.Interval = 0
' Set the event handler for receiving an alert.
AddHandler alerter.Alert, New OracleAlerterAlertEventHandler(AddressOf Alerter_OnAlert)
' Start the alerter. It will wait for alerts and fire the OnAlert event when any is received.
alerter.Start()
' Pause the thread to wait until the alerter begins listening.
Thread.Sleep(2000)
' Another instance of OracleAlerter is used to generate the alert.
' alertGenerator uses the same connection and alert name as the alerter object.
Dim alertGenerator As New OracleAlerter
alertGenerator.Connection = con
alertGenerator.AlertName = "my_alert"
' Send an alert to the server. At this moment alerter should raise the Alert event.
alertGenerator.Signal("An alert message.")
'Make a pause to wait until the alert is created and processed.
Thread.Sleep(2000)
' Stop listening to alerts.
alerter.Stop()
Console.Read()
con.Close()
End Sub
' Simple event handler for the OnAlert event.
Public Sub Alerter_OnAlert(ByVal sender As Object, ByVal e As OracleAlerterAlertEventArgs)
Console.WriteLine(("Got an alert: " & e.AlertMessage))
End Sub