Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista Tutorial - Is there a race condition reading the log?

Reply
 
Old 09-16-2008   #1 (permalink)
RickB
Guest


 
 

Is there a race condition reading the log?

# Return all events that have occured since a particular one ($start)
# If $start is negative, begin that many records from the current end
of log.
function read_log ([int]$start)
$log = new-object system.diagnostics.eventlog("MyCustApp")
if ($start -lt 0) {$start = $log.entries.count +
$log.entries[0].Index + $start}
if ($start -lt $log.entries[0].Index){$start =
$log.entries[0].Index}
$start = $start - $log.entries[0].Index - 1
while (++$start -lt $log.entries.count) {
$log.entries.item($start) }
}

If the $start message number is far enough back in the log it might
take a while to process all the messages. During that time it's
likely that new messages will be added. When I first created the log
and started reading it I didn't look at $log.entries[0].Index. Then
all hell broke loose when the log got big enough for messages to roll
off the back and $start no longer started in the right place. It
essentially skipped loads of records.

$start - $log.entries[0].Index takes care of that problem.

But now I'm worried about what will happen if a job that reads the log
happens to be reading when messages roll off. Imperically, it seems
as though a bunch of messages will be skipped because the event index
numbers will shift during processing.

Any thoughts or experience with this?

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Race Driver: GRID Gaming
VPC IM driver(VMNetSrv.sys) race condition with nVidia nForce Ethe Virtual PC
OTish, a race Vista General
IE 7 cannot run, DoS condition Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46