---
title: "Watching your computer breath using FileSystemWatcher"
url: "https://osherove.com/blog/2007/7/12/watching-your-computer-breath-using-filesystemwatcher.md"
canonical: "https://osherove.com/blog/2007/7/12/watching-your-computer-breath-using-filesystemwatcher.html"
published: "2007-07-12T13:07:35"
updated: "2007-07-12T13:07:35"
tags: [".NET", ".Net 2.0", ".Net Original"]
author: "Roy Osherove"
description: "Breath is the only word that came to mind to describe the regular second to second operations your computer does just to keep itself in the current state while preparing for the next states (in terms of temporary files,…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Watching your computer breath using FileSystemWatcher

By Roy Osherove July 12, 2007 In [.NET](https://osherove.com/blog/category/net), [.Net 2.0](https://osherove.com/blog/category/net-2-0), [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published July 12, 2007; technical details may be outdated.

_Breath_ is the only word that came to mind to describe the regular second to second operations your computer does just to keep itself in the current state while preparing for the next states (in terms of temporary files, background processes and more).

Here's a nice exercise you can do:

- Create a new console application
- Paste in this code for the Main() method:

```
static void Main(string[] args)
        {
            FileSystemWatcher watcher = new FileSystemWatcher("c:\\");
            watcher.IncludeSubdirectories = true;
            watcher.Changed+=delegate(object sender, FileSystemEventArgs e)
                                 {
                                     string file = Path.GetFileName(e.FullPath);
                                     string dir = Path.GetDirectoryName(e.FullPath);
                                     Console.WriteLine("{0} was {1} in {2}",file,e.ChangeType,dir);
                                 };
            watcher.EnableRaisingEvents = true;
            Console.Read();
        }
```

Press Ctrl+F5 and just watch the screen.

Yeah, you have fancier tools([this](http://www.microsoft.com/technet/sysinternals/FileAndDisk/Filemon.mspx) or [this](http://www.microsoft.com/technet/sysinternals/SystemInformation/processmonitor.mspx)) to do this job better, but it's nice to have this kind of ability built into the framework, and it's an eye opener just how much stuff goes on when you don't do _anything_ on your computer.

If you're interested in some tips on better usage with the FileSystemWatcher, [take a look here](http://weblogs.asp.net/ashben/archive/2003/10/14/31773.aspx).

## More in .NET

[All posts in .NET](https://osherove.com/blog/category/net)

- Jul 28, 2007

    ### [Visual Web GUI Helps me Write in Winform and run as ASP.NET](https://osherove.com/blog/2007/7/28/visual-web-gui-helps-me-write-in-winform-and-run-as-aspnet.html)

- Jul 28, 2007

    ### [Hotfix request Web Submission form could be a life saver](https://osherove.com/blog/2007/7/28/hotfix-request-web-submission-form-could-be-a-life-saver.html)

- Jun 29, 2007

    ### [Israeli .NET Bloggers Update](https://osherove.com/blog/2007/6/29/israeli-net-bloggers-update.html)

- Jun 21, 2007

    ### [Blow to open source on VS.NET: VSIP License forbids Open Source](https://osherove.com/blog/2007/6/21/blow-to-open-source-on-vsnet-vsip-license-forbids-open-sourc.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
