问题描述
Hi,大家好,我在用FileSystemWatcher监视某个目录的时候出现了问题,在往被监视的目录拷贝文件的时候Create事件似乎不能被触发(请看下面的程序),我把一个txt文件从C盘的根目录拷贝到C:ABC目录下,但是并没有触发事件,弹出消息框,请问是怎么回事,谢谢!-------------------------------------------PrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.LoadDimwatcherAsNewFileSystemWatcherwatcher.Path="C:ABC"watcher.NotifyFilter=(NotifyFilters.AttributesOrNotifyFilters.LastAccessOrNotifyFilters.LastWriteOrNotifyFilters.CreationTimeOrNotifyFilters.Size)watcher.Filter="*.txt"AddHandlerwatcher.Created,AddressOfOnChanged'AddHandlerwatcher.Changed,AddressOfOnChanged'AddHandlerwatcher.Deleted,AddressOfOnChanged'AddHandlerwatcher.Renamed,AddressOfOnRenamedwatcher.EnableRaisingEvents=TrueEndSubSubOnChanged(ByValsenderAsObject,ByValeAsFileSystemEventArgs)MessageBox.Show("test")EndSub
解决方案
解决方案二:
研究中
解决方案三:
有结果了吗?
解决方案四:
http://topic.csdn.net/u/20071216/11/6426c72a-dc33-472e-a254-f175180dccd4.html
解决方案五:
谢谢hdt的回复现在我将程序修改为:---------------------PublicwatcherAsFileSystemWatcherPrivateSubForm1_Load(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesMyBase.Loadwatcher=NewFileSystemWatcherwatcher.Path="C:ABC"watcher.NotifyFilter=(NotifyFilters.AttributesOrNotifyFilters.LastAccessOrNotifyFilters.LastWriteOrNotifyFilters.CreationTimeOrNotifyFilters.Size)watcher.Filter="*.txt"AddHandlerwatcher.Created,AddressOfOnChanged'AddHandlerwatcher.Changed,AddressOfOnChanged'AddHandlerwatcher.Deleted,AddressOfOnChanged'AddHandlerwatcher.Renamed,AddressOfOnRenamedwatcher.EnableRaisingEvents=TrueEndSubSubOnChanged(ByValsenderAsObject,ByValeAsFileSystemEventArgs)MessageBox.Show("test")EndSub---------------------但是还是没有反应,messagebox还是不出来
解决方案六:
我又试了一下,按照MSDN上写控制台程序就可以,但是现在我需要用窗体程序啊。请问怎么解决