using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using System.Threading;
namespace FilWatcher2
{
    public partial class Service1 : ServiceBase
    {
        private static String path = "d:\\yangd\\";
        private static String extractToPath = "d:\\yangd\\down";
        private FileSystemWatcher watcher=new FileSystemWatcher();
        private FastZip fz = new FastZip();
        public Service1()
        {
            InitializeComponent();
            watcher.Path = path;
            /* Watch for changes in LastAccess and LastWrite times, and 
               the renaming of files or directories. */
            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
           | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            // Only watch text files.
            watcher.Filter = "*.zip";
            watcher.Created += new FileSystemEventHandler(OnChanged);
            // Begin watching.
            watcher.EnableRaisingEvents = true;
        }        protected override void OnStart(string[] args)
        {        }
        private static void OnChanged(object source, FileSystemEventArgs e)
        {
            // Specify what is done when a file is changed, created, or deleted.
            //LibWrap.MsgBox(0, e.FullPath, e.FullPath, 0);            extract(e.FullPath);        }        private static void extract(String fullpath) {
           
            FastZip fz = new FastZip();
           fz.ExtractZip(fullpath, extractToPath, ""); 此处出错说fullpat制定的zip文件正在被其它一个程序使用。        }
        protected override void OnStop()
        {
            watcher = null;
            fz = null;
        }
    }
}

解决方案 »

  1.   

    你是怎么changed的?修改后没有关闭?
    2 是你的"d:\\yangd\\down低下有没有重名的zip文件
      

  2.   

    解决拉,娃哈哈,
    我加了 这三行就转了
            watcher.Changed += new FileSystemEventHandler(OnRenamed);
            watcher.Created += new FileSystemEventHandler(OnChanged);
            watcher.Deleted += new FileSystemEventHandler(OnRenamed);
            watcher.Renamed += new RenamedEventHandler(OnRenamed);
            private static void OnRenamed(object source, FileSystemEventArgs e)
            {
                // Specify what is done when a file is changed, created, or deleted.
                //LibWrap.MsgBox(0, e.FullPath, e.FullPath, 0);            //extract(e.FullPath);        }
    发分拉