• λ我爱Aspx >> Asp.Net >> Create and Control Windows Services--Add File-Monitoring Functionality[等级:高级]
  • Create and Control Windows Services--Add File-Monitoring Functionality[等级:高级]

  • :aspxer  Դ:internet  :2007-5-28 20:37:30  ؼ:
  • public class PlatformInvokeKernel32

    {

    [sysimport(dll="kernel32", charset=System.Runtime.InteropServices.CharSet.Auto)]

    public static extern int

    GetDriveType (string lpRootPathName);

    }

    This code simply forwards all calls using PlatformInvokeKernel32.GetDriveType() to the associated function in kernel32.dll. To get the drive type for each drive in the array, check the value returned from the call to the enumerated type win from the Microsoft.Win32.Interop namespace:

    string[] drives = Environment.GetLogicalDrives();

    // create filesystem watchers for

    // local fixed drives

    foreach (string curDrive in drives )

    {

    if (

    PlatformInvokeKernel32.GetDriveType

    (curDrive) == win.DRIVE_FIXED)

    {

    // create a FileSystemWatcher

    }

    }

    Now that you@#ve created the FileSystemWatcher objects, you must implement the event handlers for the four file notification events: creating, changing, deleting, and renaming files. You@#ll create performance counters that convey information to the user visually—one for each event. For more information on file notification event handlers and creating performance counters, download the code that accompanies this article. To create a performance counter, use the PerformanceCounter class specified in the System.Diagnostics namespace. When you call the file change event handler, it simply increments the proper performance counter by 1:

    Ҷƪл˵?
  • һƪCreate and Control Windows Services--Control Your Service[等级:高级]
    һƪCreate and Control Windows Services--introduction[等级:高级]