I simply just put a Thread.sleep in a while loop. Is that the best approach? My issue now if that I receive several events and in the UI that I need to create and wrap this with, I only should update it once. Here is output when I print to a new XPS file in that watched directory:

ChangeType: Created, FullPath: D:\tmp\blah.xps, Name: blah.xps
ChangeType: Deleted, FullPath: D:\tmp\blah.xps, Name: blah.xps
ChangeType: Created, FullPath: D:\tmp\blah.xps, Name: blah.xps
ChangeType: Changed, FullPath: D:\tmp\blah.xps, Name: blah.xps

Here the the watcher.fsx:

#light

let watcher = new System.IO.FileSystemWatcher(Path= @"D:\tmp")
let printWatcherEvent(args : System.IO.FileSystemEventArgs) =
printfn "ChangeType: %O, FullPath: %s, Name: %s" args.ChangeType args.FullPath args.Name

watcher.Changed |> IEvent.listen printWatcherEvent
watcher.Created |> IEvent.listen printWatcherEvent
watcher.Deleted |> IEvent.listen printWatcherEvent

watcher.EnableRaisingEvents <- true

open System.Threading
while true do
Thread.Sleep 1000

Any idea how I might be able to only bubble up one event? Perhaps I need to disable raising events after receiving the first one and reenable after a short period of time.

Cameron

By on 5/20/2008 4:56 PM ()

To answer you first question, this seems to do the trick:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 

#light

open System.Windows.Forms

let watcher = new System.IO.FileSystemWatcher(Path= @"C:\misc")
let printWatcherEvent(args : System.IO.FileSystemEventArgs) =
  printfn "ChangeType: %O, FullPath: %s, Name: %s" args.ChangeType args.FullPath args.Name
  
watcher.Changed |> IEvent.listen printWatcherEvent
watcher.Created |> IEvent.listen printWatcherEvent
watcher.Deleted |> IEvent.listen printWatcherEvent

watcher.EnableRaisingEvents <- true

let form = new Form(Visible=false)
Application.Run()

By on 6/7/2008 11:55 PM ()

Also you don't need to create the dummy form, so a simple call to System.Windows.Forms.Application.Run() is all you need.

don

By on 6/7/2008 11:57 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper