tags:

views:

48

answers:

3

Hi guys. i have a [self parseXMLFileAtURL:path] method. is there anyway of stopping it midway? like terminating the method.

Reason for doing is because im running an apache http server on one pc and if the server is not running, the app will 'hang' if this method is called. so i want to to something like terminating the method after a certain amount of seconds , 5s maybe. and display an alert message.

A: 

A method is just a C(++) function, so there really no way to stop it.

John Smith
That's not true. While most aren't clean, there are several ways to stop the execution of a function.
zneak
+1  A: 

I'm pretty sure that you could try installing a signal handler with sigaction to handle SIGALRM and use the alarm function. There is, however, probably a better solution using the Cocoa framework. I'll leave this here, but it's probably not the easiest way.

zneak
+5  A: 
Steve
+1 yup, that's better than my suggestion.
zneak
hmm could u give an answer on how to kill the method? on a different thread.
Kenneth
@kenneth: simple; Scroll to the bottom of the linked document (I think their point about memory management should be very carefully considered. If you truly kill the thread, you're bound to have memory issues) http://developer.apple.com/iphone/library/documentation/cocoa/Conceptual/Multithreading/CreatingThreads/CreatingThreads.html#//apple_ref/doc/uid/10000057i-CH15-SW2
Steve
hmm i think im going to stick with the request method :) . one question though, how do you set the request result to a data object? i mean ur last line, responseData(I presume its a data object)
Kenneth
@kenneth: WHOOPS! That's what I get for copy-paste. I updated the post.
Steve
You can use a shorter timeout interval instead of trying to cancel the request.
falconcreek
@falconcreek; yes, that's the point.
Steve
cool it works great! thanks for everything.
Kenneth
@kenneth: no problem... it was sorta weird for me the first time, so I'm glad I could help.
Steve