It checks the event type and fires SQL stored proc if matched
Main Topics
Browse All TopicsHi,
I wrote a little console application which monitors the windows event log for new entries.
In order to get the console app to stay alive I put the thread to sleep.
My question is:
While the thread is asleep, would the event get caught? If so, how ... i.e. does the thread get awoken or is the event done on a seperate thread, or even the events will get queued up until the thread is awake again.
Thanks for help
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If this is Console application, you need to find the way to wait for user input, for example:
Press any key to continue...
and after pressing key exit. All time when it is active, it monitors Event Log. I don't know how this can be implemented in the Console application. Maybe you need Windows Service or Windows application which adds icon to system tray and allows to select "Exit" from the context menu. But main question is: how do you want this application to look like? Should it have user interaction, how should it be started and stopped?
You could either create a thread to handle the events and come up with some "stop" mechanism for the main thread, or just do something like the example from help below (excuse the vb but you get the idea). No reason it wouldn't work in a console. As AlexFM mentions, a service might be more appropriate in which case your code is threaded anyway.
Class MySample
' This member is used to wait for events.
Private Shared signal As AutoResetEvent
Public Shared Sub Main()
Dim myNewLog As New EventLog()
myNewLog.Log = "MyCustomLog"
AddHandler myNewLog.EntryWritten, AddressOf MyOnEntryWritten
myNewLog.EnableRaisingEven
signal = New AutoResetEvent(False)
signal.WaitOne()
End Sub ' Main
Public Shared Sub MyOnEntryWritten(ByVal [source] As Object, ByVal e As EntryWrittenEventArgs)
signal.Set()
End Sub ' MyOnEntryWritten
End Class ' MySample
[C#]
using System;
using System.Diagnostics;
using System.Threading;
class MySample{
// This member is used to wait for events.
static AutoResetEvent signal;
public static void Main(){
EventLog myNewLog = new EventLog();
myNewLog.Log = "MyCustomLog";
myNewLog.EntryWritten += new EntryWrittenEventHandler(M
myNewLog.EnableRaisingEven
signal = new AutoResetEvent(false);
signal.WaitOne();
}
public static void MyOnEntryWritten(object source, EntryWrittenEventArgs e){
signal.Set();
}
}
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button in the upper-left corner of the page.
Business Accounts
Answer for Membership
by: AlexFMPosted on 2006-04-06 at 04:45:30ID: 16390788
I guess you are talking about EventLog class. It must have it's own thread and invoke client's event handlers in the context of this thread. This means, event handlers are invoked immediately even when main thread sleeps.
What does your program do after creating EventLog and subscribing to events? What does it do when log is changed? I am not sure that console application is appropriate type for this task.