首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

为什么小弟我这段代码不能监控到文件覆盖

2012-02-28 
为什么我这段代码不能监控到文件覆盖C# codeusing Systemusing System.Collections.Genericusing System

为什么我这段代码不能监控到文件覆盖

C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace WindowsFormsApplication1Test{    public partial class Form1 : Form    {       public Form1()        {            InitializeComponent();            FileSystemWatcher watcher = new FileSystemWatcher();            watcher.Path = @"D:\";            watcher.NotifyFilter = NotifyFilters.FileName;            watcher.Filter = "*.xls";            watcher.Changed += new FileSystemEventHandler(OnCreate);            watcher.Created += new FileSystemEventHandler(OnCreate);             //watcher.Deleted += new FileSystemEventHandler(OnDelete);            watcher.EnableRaisingEvents = true;        }       private static void OnCreate(object source, FileSystemEventArgs e)       {           if (File.Exists(e.FullPath) && e.Name.Substring(0, 1) != "~")           {               System.Diagnostics.Process.Start(e.FullPath);               //MessageBox.Show(e.Name.Substring(0,1));           }       }    }}






为什么我这段代码不能监控到文件被覆盖呢?我需要在D盘下有excel文件被创建或者覆盖的时候打开该文档,现在创建已经正常打开了,可是覆盖却不行?

[解决办法]
你觉得怎样算覆盖呢,如果覆盖是不是或有其他信息的更高,比如时间变化,参数中好像没有覆盖的概念
[解决办法]
应该windows系统机制造成的,再根据NotifyFilters.LastWrite的时间间隔进行过滤可以判断

热点排行