title: Obj-C: Checking if a window exists in a thread
body: <p>He, I programmatically create a window in a thread when a button in my main window is clicked. If this button is clicked again, the window closes. Fine. But when the user closes the window via its close button, the thread isn't aware of that, running on. And if the user clicks on the button in the main window, the thread is trying to close the window and the app is crashing. So I need to check within the thread if the window exists. How to do that? Thanks</p>
  
  <pre><code>-(void)prefsWindow:(id)sender {
      NSRect frame = NSMakeRect(200, 200, 640, 480);
      NSWindow *pwindow  = [[NSWindow alloc] initWithContentRect:frame
                                                       styleMask:NSTitledWindowMask 
                                                         backing:NSBackingStoreBuffered
                                                           defer:NO];
      [pwindow center];
      [pwindow makeKeyAndOrderFront:NSApp];
      while (prefsA==1) {
  
          usleep(250000);}
      [pwindow close];
      [NSThread exit];
  }
  </code></pre>