Skip navigation.
 
mlrunloops and NSURLConnection
FROM : Torsten Curdt
DATE : Sat May 31 15:28:29 2008

A bit puzzled ...seems like I need some advise here.

From a NSWindowController I create a modal dialog

  [NSApp runModalForWindow:[self window]];

On a button click I am trying to use NSURLConnection to do retrieve 
information in a asynchronous fashion

  connection = [[NSURLConnection alloc] initWithRequest:request 
delegate:self];

Unfortunately this only works when I afterwards enter this runloop

    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    while(!terminated) {
        if (![[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode 
beforeDate:[NSDate dateWithTimeIntervalSinceNow:100000]]) {
            break;
        }
        [pool release];
        pool = [[NSAutoreleasePool alloc] init];
    }
    [pool release];

(the connectionDidFinishLoading:/connection:didFailWithError: 
terminates the above loop)

Now I am a bit surprised. Shouldn't runModalForWindow: do pretty much 
the same thing? The documentation states

"By default, for the connection to work correctly the calling thread’s 
run loop must be operating in the default run loop mode. See 
scheduleInRunLoop:forMode: to change the runloop and mode."

But I am a bit lost what to do with that information. I would assume 
that

  scheduleInRunLoop:[NSRunLoop currentRunLoop] 
forMode:NSDefaultRunLoopMode

is the default anyway. Nevertheless I am targeting 10.4 and this is 
only available since 10.5.

I found this response from Fraser

http://lists.apple.com/archives/aperture-dev/2008/Feb/msg00036.html

...but I would like to understand the "why". Do I really have to spawn 
another thread for this? Or is it OK to process the run loop like 
shown above? I have the feeling I am somehow fighting the framework 
again here.

Comments?

cheers
--
Torsten_______________________________________________

Cocoa-dev mailing list (<email_removed>)

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:
http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>

This email sent to <email_removed>

Related mailsAuthorDate
mlrunloops and NSURLConnection Torsten Curdt May 31, 15:28
mlRe: runloops and NSURLConnection Michael Vannorsdel May 31, 16:09
mlRe: runloops and NSURLConnection Torsten Curdt May 31, 17:07
mlRe: runloops and NSURLConnection Jens Alfke May 31, 18:55
mlRe: runloops and NSURLConnection Michael Vannorsdel May 31, 19:03
mlRe: runloops and NSURLConnection Torsten Curdt May 31, 19:14
mlRe: runloops and NSURLConnection Jens Alfke May 31, 19:54
mlRe: runloops and NSURLConnection Jean-Daniel Dupas May 31, 19:58
mlRe: runloops and NSURLConnection Torsten Curdt Jun 1, 14:27
mlRe: runloops and NSURLConnection Torsten Curdt Jun 1, 14:28
mlRe: runloops and NSURLConnection Jean-Daniel Dupas Jun 1, 18:18