public VolumeWatcherHelper(VolumeWatcher vw) { outer = vw; OSXUtils.ApplicationHelper.ExecuteWhenLaunched(delegate { using (NSAutoreleasePool pool = new NSAutoreleasePool()) { NSNotificationCenter nc = NSWorkspace.SharedWorkspace.NotificationCenter; nc.AddObserver(this, new Selector("ev_VolumeDidMount:"), new NSString("NSWorkspaceDidMountNotification"), null); nc.AddObserver(this, new Selector("ev_VolumeDidUnmount:"), new NSString("NSWorkspaceDidUnmountNotification"), null); nc.AddObserver(this, new Selector("ev_VolumeWillUnmount:"), new NSString("NSWorkspaceWillUnmountNotification"), null); } }); }
void ev_VolumeChanged(VolumeWatcher sender, VolumeWatcherEvent evt, string volume) { if (!_fullpath.StartsWith(volume)) { return; } Trace("ev_VolumeChanged " + evt + ": " + volume); if (evt == VolumeWatcherEvent.DidMount) { _CheckAvailable(false); } else if (evt == VolumeWatcherEvent.WillUnmount || evt == VolumeWatcherEvent.DidUnmount) { _CheckAvailable(true); // must stop watcher on WillUnmount so we don't block unmount } }
public VolumeWatcherHelper(VolumeWatcher vw) { outer = vw; OSXUtils.ApplicationHelper.ExecuteWhenLaunched(delegate { using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { NSNotificationCenter nc = NSWorkspace.SharedWorkspace.NotificationCenter; nc.AddObserver(this, new Selector("ev_VolumeDidMount:"), new NSString("NSWorkspaceDidMountNotification"), null); nc.AddObserver(this, new Selector("ev_VolumeDidUnmount:"), new NSString("NSWorkspaceDidUnmountNotification"), null); nc.AddObserver(this, new Selector("ev_VolumeWillUnmount:"), new NSString("NSWorkspaceWillUnmountNotification"), null); } }); }
public void Initialize() { _volwatcher = new VolumeWatcher(); _volwatcher.VolumeChanged += ev_VolumeChanged; ThreadPool.QueueUserWorkItem(delegate { _CheckAvailable(false); }); }