Re: Exiting a Windows Event Log Application - Windows NT

This is a discussion on Re: Exiting a Windows Event Log Application - Windows NT ; "ThreadingNewbie" wrote in message news:69fee8ae.0306231933.3eec4cc4@posting.google.c om... > Hi all: > > I have a windows console application that is used for Windows Event > Log Monitoring. I do so by spawning a thread that listens for any > notifications from ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Re: Exiting a Windows Event Log Application

  1. Re: Exiting a Windows Event Log Application

    "ThreadingNewbie" wrote in message
    news:69fee8ae.0306231933.3eec4cc4@posting.google.c om...
    > Hi all:
    >
    > I have a windows console application that is used for Windows Event
    > Log Monitoring. I do so by spawning a thread that listens for any
    > notifications from the System Event Viewer for new events. I have
    > done this by using WaitSingleObject. Below is the snippet of code:
    >
    > while (WaitForSingleObject(hEvent, INFINITE) == WAIT_OBJECT_0)
    > {
    > // read the event log for the new events
    > }
    >
    > I was wondering what is the best way to exit out of such an
    > application. Do I have to spawn a new thread that listens for the
    > user's intention to quit? I am a little new to threading
    > synchronization in Windows, so any ideas are appreciated.
    >
    > Thanks,
    > Sylvia.


    If you're using a GUI, you might be interested in MsgWaitForMultipleObjects
    (you can use it to wait on just one object, actually). This allows you to
    simultaneously wait for objects to become signaled and wait for messages to
    be posted to your message queue. You should run a while(PeekMessage(....))
    { } loop when MsgWaitForMultipleObjects indicates that you've got a message
    to read instead of GetMessage(), though, because MsgWaitForMultipleObjects
    has already waited for the message(s) to be posted.

    Another option could be to use WaitForMultipleObjects on two events and
    signal the second event from your GUI/user interaction/whatever thread when
    you want your eventlog watcher thread to quit.



  2. Re: Exiting a Windows Event Log Application

    Hi: That worked great! Thank you for your suggestion.

    Sylvia.

+ Reply to Thread