Re: Avoiding UI hangs
Re: Avoiding UI hangs
- Subject: Re: Avoiding UI hangs
- From: Anthony Duer <email@hidden>
- Date: Sun, 4 Sep 2005 03:08:33 -0700
Hey Sanri,
You've actually got most of it down. However, NSAutoreleasePool isn't
what you need to create a new thread to avoid hanging your UI during
upload. To spawn a thread, use this:
....
[urlHandle setPutFile:fileToUpload];
[NSThread detachNewThreadSelector: @selector(startUpload:)
toTarget: self withObject: urlHandle];
Your startUpload method will then have to be adjusted slightly:
-(void)startUpload:(CURLHandle *)handle
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[handle prepareAndPerformCurl];
if (![[handle curlError] isEqualToString:@""])
{
[self performSelectorOnMainThread: @selector(failed:)
withObject: [handle curlError] waitUntilDone: NO];
//This should be performed on the main thread since it involves
the UI.
//NSBeginAlertSheet(@"Upload
error",@"Ok",nil,nil,g_finPrincipale,self,nil,nil,nil,[NSString
stringWithFormat:@"Upload failed\nHere's the error generated by
CURL:\n\n %@",[handle curlError]]);
}
[pool release];
[NSThread exit];
}
That should be it to getting your thread going. Good luck. :)
~Anthony Duer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden