SDF Sample: Knowing when a storage device is inserted or removed

Sometimes we tend to forget just how useful the Smart Device Framework really is.  There are tons of little gems in it that we put in there, some times years ago, and then we forget about it.  I have a general idea of what all is there, but by no means can I tell you everything, so when I need a feature in an app, I always go look to see if we’ve already done it.

Unfortunately we tend to lack concrete examples of how a lot of it can help you in your everyday work.  In an effort to rectify that, over the coming months all of us here at OpenNETCF will be blogging short snippets of cool, useful stuff you can do.  We also are taking requests.

So here’s one.  

I have a device and we want to know when a storage device (USB, CF, PCMCIA, SD, etc.) is either inserted or removed.  What does the SDF do for me?


[Developed and tested on an OLDI 56SAM-400 800MHz x86 device running CE 5.0]

private DeviceStatusMonitor m_diskMonitor;

public MyClass()

    m_diskMonitor = new DeviceStatusMonitor(DeviceStatusMonitor.FATFS_MOUNT_GUID, false);
    m_diskMonitor.DeviceNotification += FATMounted;


void FATMounted(object sender, DeviceNotificationArgs e)
    Trace2.WriteLine(string.Format(“FAT device ‘{0}’ {1}mounted”, e.DeviceName, e.DeviceAttached ? “” : “un”));

The DeviceStatusMonitor ctor’s first parameter can be a few things – I’ve chosen FAT file system (we can detect a CD too!).

The thing I don’t understand is how the hell this class ended up in the OpenNETCF.Net namespace.  Expect that to change in 2.2.  I’ll probably deprecate the existing classes with a warning and move them somewhere that it makes sense.  I may also streamline the usage as well.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s