Skip navigation.
 
mlRe: Self terminating popup window - need help
FROM : j o a r
DATE : Fri Apr 15 21:20:04 2005

On 14 apr 2005, at 23.41, Dan Yocom wrote:

>    I created a subclass of NSWindow that automatically closes the
> window after three seconds.


That's not a good reason to subclass. Let's think of some other design.

(Cocoa developers try to avoid subclassing. We have a lot of useful 
alternatives to subclassing, mainly categories and delegation. Search 
the list archives and the Cocoa web resources (look in the regular 
email from list-mom Mmalc for links) for more information on these 
topics.)

> The subclass works as it should when
> called from a normal objective-C routine/function. However, if I call
> it from within a NSThread I create, it will popup but not close. Does
> anyone know why it won't work porpperly when call from within an
> NSThread?


Yes, if you set a timer to close that window, the timer will be 
depending on the normal operation of the run loop in that thread. If 
you are doing a synchronous operation, never letting the run loop - 
well, run - the timer is never going to fire.

The easiest thing to do would probably be to set the timer in the 
main thread. Something like this (note that I expect you to already 
have a window called "myWindow"):

- (void) startLongOperation
{
    // Open window
    [myWindow makeKeyAndOrderFront: nil];

    // Set the timer to close the window
    [myWindow performSelector: @selector(orderOut:) withObject: nil 
afterDelay: 3.0];

    // Launch operation
    [NSThread detachNewThreadSelector: @selector(theOperation) 
toTarget: self withObject: nil];
}

j o a r

Related mailsAuthorDate
mlSelf terminating popup window - need help Dan Yocom Apr 14, 23:41
mlRe: Self terminating popup window - need help Joshua D. Orr Apr 15, 00:33
mlRe: Self terminating popup window - need help Dan Yocom Apr 15, 16:26
mlRe: Self terminating popup window - need help Lindsey Spratt Apr 15, 17:35
mlRe: Self terminating popup window - need help Joshua Orr Apr 15, 18:55
mlRe: Self terminating popup window - need help j o a r Apr 15, 19:50
mlRe: Self terminating popup window - need help j o a r Apr 15, 21:20