MonitorEventHandler Delegate
Represents the method that will handle the
TraceEvent event of the
DbMonitor class.
The following sample shows how to enable and disable monitoring of database activity in your application.
|
|---|
static void OnEvent(object sender, MonitorEventArgs e)
{
if (e.TracePoint==MonitorTracePoint.BeforeEvent)
{
Console.WriteLine("Description: " + e.Description);
Console.WriteLine(" Extra info: " + e.ExtraInfo);
}
}
[MTAThread]
static void Main(string[] args)
{
PgSqlConnection pgSqlConn = new PgSqlConnection(
"host=server;database=test;user id=postgres;");
PgSqlMonitor pgSqlMonitor = new PgSqlMonitor();
pgSqlMonitor.TraceEvent += new MonitorEventHandler(OnEvent);
pgSqlMonitor.IsActive = true;
PgSqlCommand pgSqlCommand = new PgSqlCommand("select count(*) from Test.Dept",pgSqlConn);
pgSqlConn.Open();
Console.WriteLine(pgSqlCommand.ExecuteScalar());
pgSqlConn.Close();
pgSqlMonitor.TraceEvent -= new MonitorEventHandler(OnEvent);
Console.ReadLine();
} |
|
|---|
Sub OnEvent(ByVal sender As Object, ByVal e As MonitorEventArgs)
If e.TracePoint = MonitorTracePoint.BeforeEvent Then
Console.WriteLine("Description: " & e.Description)
Console.WriteLine(" Extra info: " & e.ExtraInfo)
End If
End Sub
<MTAThread()> _
Sub Main()
Dim pgSqlConn As PgSqlConnection = New PgSqlConnection( _
"host=server;database=test;user id=postgres;")
Dim pgSqlMonitor As PgSqlMonitor = New PgSqlMonitor
AddHandler pgSqlMonitor.TraceEvent, AddressOf OnEvent
pgSqlMonitor.IsActive = True
Dim pgSqlCommand As PgSqlCommand = New PgSqlCommand("select count(*) from Test.Dept", pgSqlConn)
pgSqlConn.Open()
Console.WriteLine(pgSqlCommand.ExecuteScalar())
pgSqlConn.Close()
RemoveHandler pgSqlMonitor.TraceEvent, AddressOf OnEvent
Console.ReadLine()
End Sub |