Chapter 2: Creating and managing Windows services includes understanding Windows services; creating Windows services; handling events and logging information from a Windows services application; adding installers, specifying security context and installing and uninstalling a Windows services.
Trang 1! "# $ %&
Trang 5The Services window of the Administrative Tools component 5
Trang 10,
Trang 15The Visual Studio NET New Project dialog box B5
Trang 20protected override void OnStart(string[] args)
StreamWriter sr = new StreamWriter(fs);
protected override void OnStop()
Trang 255
private System.Diagnostics.EventLog eventLog1;
…
private void CreateEventLog()
{ eventLog1 = new System.Diagnostics.EventLog();
Trang 34! & '
See Text Book page 77-82
Trang 35.5
Trang 36$
Trang 37.8
, (
Trang 40#
( ( +
!
private ServiceController serviceCtr1;
this.serviceCtr1 = new ServiceController();
this.serviceCtr1.MachineName = “.";
this.serviceCtr1.ServiceName = "DBWriter";
Trang 44if(System.DateTime.Now.Hour <= 24 )
MyServiceController.ExecuteCommand(220);
}
Trang 4505
protected override void OnCustomCommand(int command)
{ FileStream FS = new FileStream(@"c:\MyWindowsService_CSharp.txt",
SR.WriteLine("Good Everning");
SR.Flush();
} }
Trang 46J !
static void Main(string[] args)
{ ServiceController MyServiceController = new ServiceController(); ServiceController[] services= ServiceController.GetServices(); IEnumerator enumerator = services.GetEnumerator();
while (enumerator.MoveNext())
{
Console.WriteLine(((ServiceController)_
enumerator.Current).ServiceName); }
Console.WriteLine("Press <Enter> to exit");
Console.Read();
... class="page_container" data-page="45">05
protected override void OnCustomCommand(int command)
{ FileStream FS = new FileStream(@"c:\MyWindowsService_CSharp.txt",... 36
$
Trang 37.8
,... 44
if(System.DateTime.Now.Hour <= 24 )
MyServiceController.ExecuteCommand(220);
}