Excel Onchanged事件不断被调用 [英] Excel Onchanged Event keeps getting called

查看:51
本文介绍了Excel Onchanged事件不断被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写excel文件。每当excel文件发生变化时,我都会举起一个活动。



I am writing to excel file. I am raising a event whenever the excel file changes.

private void FileChanged()
       {

           watcher.Path = DirectoryPath;
           watcher.Filter = "*.xlsx";
           watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;

           watcher.Changed += new FileSystemEventHandler(OnChanged);
           watcher.EnableRaisingEvents = true;

       }







我期待OnChanged方法在调用时调用我打开文件写,但我看到OnChanged方法不断被调用几次。



在OnChanged方法中,如果它是相同的进程,我什么都不做。只有当它是一个不同的过程然后我才能从excel文件中读取。



我们的帮助表示赞赏。




I am expecting the OnChanged method would be called when I Open the file for writing but I am seeing the OnChanged method keeps getting called several times.

In the OnChanged method I am not doing anything if it is the same process. Only if it is a different process then I am reading from excel file.

Your help is appreciated.

推荐答案

MSDN [ ^ ]写道:

公共文件系统操作可能会引发多个事件。例如,当文件从一个目录移动到另一个目录时,可能会引发几个OnChanged和一些OnCreated和OnDeleted事件。移动文件是一项复杂的操作,由多个简单操作组成,因此可以引发多个事件。同样,某些应用程序(例如,防病毒软件)可能会导致FileSystemWatcher检测到其他文件系统事件。

Common file system operations might raise more than one event. For example, when a file is moved from one directory to another, several OnChanged and some OnCreated and OnDeleted events might be raised. Moving a file is a complex operation that consists of multiple simple operations, therefore raising multiple events. Likewise, some applications (for example, antivirus software) might cause additional file system events that are detected by FileSystemWatcher.



您可能需要做的是缓冲来自 FileSystemWatcher



以下内容可能工作 [ ^ ]。



您可能想要为其他实现进行一些挖掘,因为我不熟悉它,但它似乎是可以证明是有用的起点。



享受。


What you will likely need to do is buffer the events coming out of the FileSystemWatcher.

Something like the following might work[^].

You might want to do some digging around for other implementations, as I''m not familiar with that but it seems like that could prove useful as a starting point.

Enjoy.


JSOP也有两篇文章(可能)帮助你了解一些发生的事情 - 请参阅



˚F ileSystemWatcher - Pure Chaos(第1部分,共2部分) [ ^ ]



和第2部分,特别是''quirks''



FileSystemWatcher - Pure Chaos(Part 2 of 2) [ ^ ]





''G''
JSOP also has two articles which (may) help you understand some of the things going on - see

FileSystemWatcher - Pure Chaos (Part 1 of 2)[^]

and part 2, particularly for the ''quirks''

FileSystemWatcher - Pure Chaos (Part 2 of 2)[^]


''G''


这篇关于Excel Onchanged事件不断被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆