FileSystemWatcher + timer

johndu81 2012-03-02 02:50:18
我用FileSystemWatcher监测一个文件夹,如果有新文件就运行代码。
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Created Then
If e.ChangeType = IO.WatcherChangeTypes.Created Then
Convert_Timer.Enabled = True
Convert_Timer.Interval = 2000
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objReader As New StreamReader(Application.StartupPath + "\Config.ini")
Dim sLine As String = ""
Dim arrText As New ArrayList()


Convert_Timer.Enabled = False

Try

watchfolder = New System.IO.FileSystemWatcher()
watchfolder.Path = “C:\report”

watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.Attributes

AddHandler watchfolder.Created, AddressOf logchange

watchfolder.EnableRaisingEvents = True

Catch ex As Exception
WriteLog("Reading exported report from Zenon encouter error: " + ex.Message)
End Try
End Sub
Private Sub Convert_Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Convert_Timer.Tick
MsgBox("New file!")
End Sub

如果有新文件,可以运行到Convert_Timer.Enabled = True,Convert_Timer.Interval = 2000。
但是timer下面的代码怎么都不运行。
请问怎么回事,谢谢先。
...全文
83 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
newxdlysk 2012-03-12
  • 打赏
  • 举报
回复
Thread.Sleep(1000);
johndu81 2012-03-12
  • 打赏
  • 举报
回复
真是奇怪,timer可以enable,timer里面的代码就是不运行。
大家有什么方法放一个延迟在
If e.ChangeType = IO.WatcherChangeTypes.Created Then
If e.ChangeType = IO.WatcherChangeTypes.Created Then
时间延迟
End If
End If
End Sub
johndu81 2012-03-06
  • 打赏
  • 举报
回复
timer事件不对也应该报错吧。
这是timer事件:
Convert_Timer.Tick
MsgBox("New file!")
End Sub
ccccffff 2012-03-03
  • 打赏
  • 举报
回复
Convert_Timer.Start 试试看呢,或者就是你timer事件是不是不对

16,556

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧