Implementing a Managed OnTimer Event Sink
Implementing a Managed OnTimer Event Sink
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
The following samples catch the OnTimer Method and write information to a log file. See Store Event Sink Bit Flags and Building Managed Event Sink DLLs for more information.
Visual Basic.NET
Option Explicit On Option Strict On ' Add project references to the System.EnterpriseServices, ADODB, ' Interop.Exoledb, and SignedExevtsnk .NET components. Imports System.IO Imports System.EnterpriseServices Imports Exoledb = Interop.Exoledb Imports ExevtsnkLib = SignedExevtsnk Imports ADODB Imports System.Reflection Namespace ExchangeSDK.Snippets.VBNet Public Class SystemEvents Inherits ServicedComponent Implements Exoledb.IExStoreSystemEvents ' Logfile path. Private Const LOGFILE As String = "C:\\evtlog.txt" Public Sub OnTimer(ByVal bstrURLItem As String, ByVal lFlags As Integer) _ Implements Interop.Exoledb.IExStoreSystemEvents.OnTimer ' Variables. Dim sr As StreamWriter ' Open the log file, append text to file. sr = File.AppendText(LOGFILE) Try sr.WriteLine("[VB.NET Event Sink] OnTimer()") ' Write the current time to the log. sr.WriteLine("Current time: " + DateTime.Now.ToString()) ' Write the event flag to the log. sr.WriteLine("lFlags: " & lFlags) Catch ex As Exception ' Write exception info to the log. sr.WriteLine("Exception message: " & ex.Message) sr.WriteLine("") End Try ' Close the stream writer. sr.Close() End Sub Public Sub OnMDBShutDown(ByVal bstrMDBGuid As String, ByVal lFlags As Integer) _ Implements Interop.Exoledb.IExStoreSystemEvents.OnMDBShutDown ' Implement OnMDBShutDown code here. End Sub Public Sub OnMDBStartUp(ByVal bstrMDBGuid As String, ByVal bstrMDBName As String, ByVal lFlags As Integer) _ Implements Interop.Exoledb.IExStoreSystemEvents.OnMDBStartUp ' Implement OnMDBStartUp code here. End Sub End Class End Namespace
C#
using System; using System.Reflection; using System.Diagnostics; using Exoledb = Interop.Exoledb; using ADODB; using System.EnterpriseServices; using System.IO; namespace ExchangeSDK.Snippets.CSharp { public class SystemEvents : ServicedComponent, Exoledb.IExStoreSystemEvents { // Logfile path. private const string LOGFILE = "C:\\evtlog.txt"; public void OnTimer(string bstrURLItem, int lFlags) { // Variables. StreamWriter sr; // Open the log file, append text to file. sr = File.AppendText(LOGFILE); try { sr.WriteLine ("[C# Event Sink] OnTimer()"); sr.WriteLine("Current time: " +DateTime.Now); sr.WriteLine("lFlags: " + lFlags); } catch(Exception ex) { // Write exception info to the log. sr.WriteLine("Exception message: " + ex.Message); sr.WriteLine(""); } // Close the stream writer. sr.Close(); } public void OnMDBStartUp(string bstrMDBGuid, string bstrMDBName, int lFlags) { // Implement OnMDBStartUp code here. } public void OnMDBShutDown(string bstrMDBGuid, int lFlags) { // Implement OnMDBShutDown code here. } } }
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
This topic last updated: September 2004
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.