Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
1088
|
Chapter 20: Toolbox
The notifications from SystemEvents come on a dedicated thread for raising these
events. In a Windows Forms application, you will need to get back on to the correct
user interface thread before updating a UI with any of this information, using one of
the various methods for doing so (
Control.BeginInvoke, Control.Invoke, BackgroundWorker).
See Also
See the “SystemEvents Class,” “PowerModeChangedEventArgs Class,” “Session-
EndedEventArgs Class,” “SessionEndingEventArgs Class,” “SessionSwitchEvent-
Args Class,” “TimerElapsedEventArgs Class,” “UserPreferenceChangingEventArgs
Class,” and “UserPreferenceChangedEventArgs Class” topics in the MSDN
documentation.
20.2 Controlling a Service
Problem
You need to programmatically manipulate a service that your application interacts
with.
Solution
Use the System.ServiceProcess.ServiceController class to control the service.
ServiceController allows you to interact with an existing service and to read and
change its properties. In the example, it will be used to manipulate the ASP.NET
State Service. The name, the service type, and the display name are easily available
from the
ServiceName, ServiceType, and DisplayName properties.
ServiceController scStateService = new ServiceController("COM+ Event System");
Console.WriteLine("Service ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata