Manages Oracle alerts.
The following sample shows how an alert can be received in the Start/Stop mode of OracleAlerter. We send an alert message by one instance of OracleAlerter and receive this message asynchronously using another OracleAlerter.
static void Main(string[] args) {
// Open a connection to the Oracle server.
OracleConnection con = 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.
OracleAlerter alerter = new OracleAlerter();
alerter.Connection = con;
alerter.AlertName = "my_alert";
alerter.Timeout = 5;
alerter.Interval = 0;
// Set the event handler for receiving an alert.
alerter.Alert += new OracleAlerterAlertEventHandler(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.
OracleAlerter alertGenerator = 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();
}
// Simple event handler for the OnAlert event.
public static void Alerter_OnAlert(object sender, OracleAlerterAlertEventArgs e) {
Console.WriteLine("Got an alert: " + e.AlertMessage);
}
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
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2