Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: runloops and NSURLConnection



I think you want to schedule the connection for the NSModalPanelRunLoopMode runloop mode. This is the mode that is used for modal windows.


On May 31, 2008, at 7:28 AM, Torsten Curdt wrote:

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

This email sent to email@hidden

_______________________________________________

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

This email sent to email@hidden
References: 
 >runloops and NSURLConnection (From: Torsten Curdt <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.