Visual Studio and .NET Framework Home
Parallel Reading from Security Event Log fails on Windows XP 32 Bit
as Not Reproducible
2/2/2009 10:29:58 PM
User(s) can reproduce this bug
When I read from Windows Event Log in parallel (to speed up reading) I get from the Security Event Log exceptions of the form:
Required Privilege not held and other stuff.
Visual Studio 2008 SP1
Windows XP Professional
Operating System Language
Steps to Reproduce
public static void SecurityEventLogProblem()
using (EventLog ev = new EventLog("Security"))
// ev.Entries.Count throws this one:
/* InvalidOperationException: Cannot open log Security on machine .. Windows has not provided an error code.
at System.Diagnostics.EventLog.OpenForRead(String currentMachineName)
at eventlogProblem.Program.SecurityEventLogProblem() in C:\Source\eventlogProblem\Program.cs:line 22
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
// The other thread is at
[Managed to Native Transition]
System.dll!System.Diagnostics.EventLog.EntryCount.get() + 0x24 bytes
System.dll!System.Diagnostics.EventLog.GetEntryAtNoThrow(int index = 14518) + 0x21 bytes
System.dll!System.Diagnostics.EventLog.GetEntryAt(int index) + 0x11 bytes
System.dll!System.Diagnostics.EventLogEntryCollection.this[int].get(int index) + 0xc bytes
eventlogProblem.exe!eventlogProblem.Program.SecurityEventLogProblem() Line 36 + 0x16 bytes C#
var count = ev.Entries.Count;
for (int i = (ev.Entries.Count - 1); i > (ev.Entries.Count - 100); i--)
// throws ArguemntException from time to time. It seems that the count changes
var entry = ev.Entries[i];
static void Main(string args)
for (int i = 0; i < 2; i++)
Thread t = new Thread(SecurityEventLogProblem);
Console.WriteLine("Waiting for crash");
No Exceptions when reading from Security Event Log.
On Windows Server 2008 this issue seems to be fixed although reading is much slower.
TAP Code (if applicable)
You can indicate your satisfaction with how Microsoft handled this issue by completing this quick
3 question survey
to post a comment.
Please enter a comment.
on 2/18/2009 at 1:55 PM
I'm not able to reproduce the issue with reading from the Security log on the Windows XP. I've run the app you produced on my local XP machine for about a day and haven't run into the Exception.
With respect to the other issue you brought up where accessing the Entries array sometimes throws an ArgumentException it is possible for that to happen due to a race where the data in the event log can change between when you get the count parameter and when you index into the array. To work around this issue I'd recommend that you use the Enumerator on the EventLogEntriesCollection to get at entries. While this isn't as straight forward as the indexer the code paths there shouldn't throw (HasNext() would return false).
If you're able reproduce the issue where you get an InvalidOperationException please re-active this issue or shoot me an email and I'll try to work with you to get some more information to help me investigate what's going on here. My e-mail address is matell (at) microsoft (dot) com
Thanks again for contacting us. Hopefully this workaround works for you.
SDE, Base Class Libraries
on 2/3/2009 at 6:53 PM
Thanks for your feedback.
We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Visual Studio Product Team
to post a workaround.
Please enter a workaround.
© 2014 Microsoft