|
-
Feb 9th, 2006, 05:26 PM
#1
Thread Starter
Frenzied Member
Winforms timer woes...
Hey folks,
I'm using VB 2005 Express, obviously with .NET framework 2.0, and I've run into something a little odd..
I have myself a program which runs in the background, and uses a FileSystemWatcher. It logs changes to a certain directory, indicating that users have changed settings, etc..., etc..
Anyhow, one of the apps which changes settings does it in such a way that it deletes a file, then immediately creates a new file. So, to separate this type of event from a straight up deletion event, I put this code in the event handler (deletedlist is just an arraylist):
VB Code:
Private Sub FW_Deleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
deletedlist.Add(e.FullPath.ToUpper)
deletetime.Interval = 2000
deletetime.Enabled = True
End Sub
Private Sub deletetime_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
deletetime.Stop() 'This is a "run once" timer.
For i As Integer = 0 To deletedlist.Count - 1
Dim SW As New IO.StreamWriter(path + "global.log", True)
Dim datestr As String = Date.Now.ToShortTimeString + " on " + Date.Now.ToShortDateString
SW.WriteLine(deletedlist(i).ToString + " was deleted at " + datestr)
SW.Close()
Threading.Thread.Sleep(500) 'Avoid windows file conflicts.
Next
deletedlist.Clear() 'Remove all items from list, as they've been handled.
End Sub
You will notice neither sub has a handles clause at the end. Fair enough. Here they are in the forms load event:
VB Code:
AddHandler FW.Deleted, AddressOf FW_Deleted
AddHandler deletetime.Tick, AddressOf Me.deletetime_Tick
So, you would think this would work eh? The tick event never fires. Now, Sometimes I think I know what I'm doing, so I tried just dragging and dropping instead of using AddHandler, just incase I've got that all wrong. Still no dice.
I then started a new project, drag and dropped a winforms timer, and a filesystemwatcher object onto the form, and basically did the same thing without any other code, and it never fires the tick sub. I remove the code from the filesystemwatcher's event handler, stick it in a generic button click sub, and it works fine. Logically, next, I put a breakpoint on the filesystemwatcher's event code - as soon as I delete a file, boom, it fires. Line by line I step through the enabling and setting of the interval.. yet the tick event (which I've also got a breakpoint at) never fires.
Finally, I replace my Winforms timer with a System.Timers.Timer, change the words tick to elapsed, and everything's fine.
Any clue why the winforms timer.Tick event will not fire if Enabled is turned on by a deleted event of a FileSystemWatcher?
Bill
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|