title: How to use FileSystemWatcher in F#
body: <p>I want to watch a directory for file changes (create, edit, rename, delete) and do something, such as calling a function, when a change is detected. From what I can tell, <a href="https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx" rel="nofollow">FileSystemWatcher</a> should do this. However, there is no sample code for F# on the documentation page, and elsewhere on the web seems scarce as well.</p>
  
  <p>From what I've found, the following is at least part of the answer:</p>
  
  <pre><code>let fileSystemWatcher = new FileSystemWatcher()
  
  fileSystemWatcher.Path &lt;- @"C:\temp" // I'm actually using a variable here
  fileSystemWatcher.NotifyFilter &lt;- NotifyFilters.LastWrite
  fileSystemWatcher.EnableRaisingEvents &lt;- true
  fileSystemWatcher.IncludeSubdirectories &lt;- true
  
  fileSystemWatcher.Changed.Add(fun _ -&gt; printfn "changed")
  fileSystemWatcher.Created.Add(fun _ -&gt; printfn "created")
  fileSystemWatcher.Deleted.Add(fun _ -&gt; printfn "deleted")
  fileSystemWatcher.Renamed.Add(fun _ -&gt; printfn "renamed")
  </code></pre>
  
  <p>That doesn't actually <em>do</em> anything, however. <a href="http://fpish.net/topic/None/59981" rel="nofollow">Some posts</a> seem to have an Async loop to react to events, but if I use the code snippets from there F# tells me that <code>Async.AwaitObservable</code> is undefined.</p>
  
  <p>I'd appreciate it if someone could provide a complete example of FileSystemWatcher's correct usage.</p>