• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSWorkspace notification being triggered twice
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSWorkspace notification being triggered twice


  • Subject: NSWorkspace notification being triggered twice
  • From: Alex Reynolds <email@hidden>
  • Date: Mon, 25 Nov 2002 01:42:58 -0500

I have a situation where I am monitoring disks being unmounted from the Finder. But the notification that I receive when this happens seems to be coming in twice and I am curious why.

When a disk is programmatically mounted, I detach a new NSThread:

------

- (void) startImageMonitoringThread:(NSString *)imageTruePath
{
ImageMonitor *imageMonitor = [[ImageMonitor alloc] init];
[NSThread detachNewThreadSelector:@selector(monitorImagesForFinderEject:) toTarget:imageMonitor withObject:imageTruePath];
}

------

I am using the following methods in my ImageMonitor class to handle this thread's behavior:

------

// selector method
- (void) monitorImagesForFinderEject:(NSString *)imageTruePath
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[self registerForWorkspaceUpdates];
[pool release];
[NSThread exit];
}

// register for disk eject/unmount updates
- (void) registerForWorkspaceUpdates
{
NSNotificationCenter *notCenter;
SEL observerMethodSEL;

observerMethodSEL = @selector(observerMethod:);
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];

// register for all notifications? probably just want the diskEject...
[notCenter addObserver:self selector:observerMethodSEL name:NSWorkspaceDidUnmountNotification object:nil];
}

// tell us if something happened
- (void) observerMethod:(NSNotification *) aNotification
{
// do something if the disk eject is noticed...
NSLog (@"method -- ImageMonitor -- observerMethod: -- NSWorkspace changed state...");
NSLog (@"method -- ImageMonitor -- observerMethod: -- %@",[[NSWorkspace sharedWorkspace] mountedLocalVolumePaths]);
}

------

Okay, so things work, but when a disk is unmounted from the Finder, NSWorkspace seems to fire the NSWorkspaceDidUnmountNotification notification twice.

Let's say I have three local volumes: "/", "/Volumes/Alex" and "/Volumes/Tim".

In my run log entry, I see the following immediately after I unmount "/Volumes/Alex":

2002-11-25 01:28:05.356 Ramallama[9646] method -- ImageMonitor -- observerMethod: -- <CFArray 0x18dc700 [0xa01303fc]>{type = mutable-small, count = 2, values = (
0 : <CFString 0x190bcd0 [0xa01303fc]>{contents = "/"}
1 : <CFString 0x190aeb0 [0xa01303fc]>{contents = "/Volumes/Tim"}
)}
2002-11-25 01:28:05.386 Ramallama[9646] method -- ImageMonitor -- observerMethod: -- NSWorkspace changed state...
2002-11-25 01:28:05.405 Ramallama[9646] method -- ImageMonitor -- observerMethod: -- <CFArray 0x18eecc0 [0xa01303fc]>{type = mutable-small, count = 2, values = (
0 : <CFString 0x1871490 [0xa01303fc]>{contents = "/"}
1 : <CFString 0x187ea50 [0xa01303fc]>{contents = "/Volumes/Tim"}

Why would the notification come in twice? I don't mind too much because the array entries are correct. I can still take this array, enumerate through it and find out what was unmounted. Still, I'm wondering if I've done something wrong.

Thanks for any pointers,

-Alex
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: (no subject)
  • Next by Date: NSFontPanel again
  • Previous by thread: Re: Ok...
  • Next by thread: NSFontPanel again
  • Index(es):
    • Date
    • Thread