runloops and NSURLConnection
runloops and NSURLConnection
- Subject: runloops and NSURLConnection
- From: Torsten Curdt <email@hidden>
- Date: Sat, 31 May 2008 15:28:29 +0200
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@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