
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Using Event Logs in Your Application
|
449
{
state = MyObject.IsProcessResponding(proc);
if (state == MyObject.ProcessRespondingState.NotResponding)
{
Console.WriteLine("{0} is not responding.",proc.ProcessName);
}
}
This code snippet iterates over all processes currently running on your system. The
static
GetProcesses method of the Process class takes no parameters and returns an
array of
Process objects with information for all processes running on your system.
Each
Process object is then passed in to your IsProcessResponding method to deter-
mine whether it is responding. Other static methods on the Process class that retrieve
Process objects are GetProcessById, GetCurrentProcess, and GetProcessesByName.
See Also
See the “Process Class” topic in the MSDN documentation.
8.6 Using Event Logs in Your Application
Problem
You need to add the ability for your application to log events that occur in your
application, such as startup, shutdown, critical errors, and even security breaches.
Along with reading and writing to a log, you need the ability to create, clear, close,
and remove logs from the event log.
Your application might need to keep track of several logs at one time. For example,
your application might use a custom log to track specific events, such as startup and
shutdown, as they