我爱Aspx >> Asp.Net >> Create and Control Windows Services--Add File-Monitoring Functionality[等级:高级]Create and Control Windows Services--Add File-Monitoring Functionality[等级:高级]
that all the necessary architecture is in place, you can add some functionality to the service. As an example, I@#ll show you how to build a file-monitoring service that monitors the local file system and notes important activity by presenting the data with a custom performance counter.
The ServiceBase class provides a couple properties all services should implement. ServiceName is the name your service uses to identify itself to the system and to applications that want to start it programmatically. For this example, the ServiceName property is "File Monitor Service." Another property is CanPauseAndContinue—set this to true so your service can support pause and continue functionality.
The OnStart() function performs the necessary initialization to start file monitoring as well as create the custom performance counters on the local system if they haven@#t been created already. The .NET Framework monitors local file system changes by implementing the FileSystemWatcher class, defined in the System.IO namespace, which allows you to specify handlers for file change notification events. In this case, you@#re interested in files that are created, changed, deleted, or renamed. Because you want to monitor file changes only on the local file system, you must enumerate all the defined drives and create a FileSystemWatcher object only on fixed drives. But the .NET Framework (as of this writing) doesn@#t contain any special functions to do this. So you must invoke the GetDriveType() API call defined in kernel32.dll on each drive in the array created from the call to GetLogicalDrives(). You can create a small class called PlatformInvokeKernel32 to wrap the API and call GetDriveType() easily:
Ҷƪл˵?
Create and Control Windows Ser..[05-28]
Create and Control Windows Ser..[05-28]
Consuming a Webservice Part 2 ..[05-28]
Creating a Webservice Part 1 o..[05-28]
一个用webservice behavior实现的..[05-28]
加强 WEB SERVICE 的安全性[05-28]
WebService Behavior的一个中文B..[05-28]
Web服务到底是什么(转)[05-28]
WEB服务有待实践的检验[05-28]
一个webseveice的例子[05-28]