Asynchronous Notification Does NOT Work
Asynchronous Notification Does NOT Work
- Subject: Asynchronous Notification Does NOT Work
- From: Bing Li <email@hidden>
- Date: Mon, 06 Jun 2011 00:20:16 +0800
Dear all,
I just learned the technique of asynchronous notification. This is the first
time for me to use it in my system. However, I got a weird problem. Only
synchronous notification works well. If replacing the synchronous
notification lines of code with asynchronous ones, it does not work.
My system is a Cocoa Application. I know RunLoop is created automatically in
such a project. So asynchronous notification should work. The primary code
is as follows.
......
// The following two lines are the parameters to be transmitted with
the notification.
NSMutableDictionary *connectionDisconnectedDictionary =
[[[NSMutableDictionary alloc] initWithCapacity:5] autorelease];
[connectionDisconnectedDictionary setObject:serviceKey forKey:@
"SERVICE_KEY"];
// This line does not work.
// [[[NSNotificationQueue alloc]
initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
enqueueNotification:[NSNotification
notificationWithName:@"CONNECTION_DISCONNECTED"
object:self userInfo:connectionDisconnectedDictionary]
postingStyle:NSPostWhenIdle];
// This line works well.
// [[[NSNotificationQueue alloc]
initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
enqueueNotification:[NSNotification
notificationWithName:@"CONNECTION_DISCONNECTED" object:self
userInfo:connectionDisconnectedDictionary] postingStyle:NSPostNow];
// It does not work.
// [[[NSNotificationQueue alloc]
initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
enqueueNotification:[NSNotification
notificationWithName:@"CONNECTION_DISCONNECTED" object:self
userInfo:connectionDisconnectedDictionary] postingStyle:NSPostASAP];
// It works
[[NSNotificationCenter defaultCenter]
postNotificationName:@"CONNECTION_DISCONNECTED" object:self
userInfo:connectionDisconnectedDictionary];
......
The registration and events code is the same. So I felt confused.
Could you please give me a hand? What reasons might cause the above problem?
Best,
Bing
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden