Tuesday, February 20, 2018

[HowTo] Detect USB device attach/detach on MacOS in C#

var fileSystemWatcher = new FileSystemWatcher("/dev");
fileSystemWatcher.Created += (s, e) => { // handle USB device arrival };
fileSystemWatcher.Deleted += (s, e) => { // handle USB device removal };
fileSystemWatcher.EnableRaisingEvents = true;

Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "enabled");


No comments:

Post a Comment