objective c - iphone - stoping a method that is running? -


Do I have a self-parseXMLFileAtURL: path] method anyway, do not interrupt it? The way to end the method.

The reason for doing this is because IM is running an Apache HTTP server on a PC and if the server is not running, the app will be 'hang' if this method is called. So I want to do something like ending the method after a few seconds seconds, maybe 5s and display a warning message

I have two suggestions ... One, if you can possibly use NSUER URL with NSUtt URL, retrieve data; Which gives you better control over things like timeouts.

  NSError * error; NSURLResponse * response; NSMutableURLRequest * Request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: @ "http: // ..."] Cash Policy: NSURLRequestReloadIgnoringLocalCacheData Timeout Interval: 60.0]; // If you need it, then not sure, but I also post it too, so whatever: [Request HTTTPMethod: @ "GET"]; NSDT * responseData = [sending NSRR connection synchronous: Response returning request: and response error: and error]; NSString * xml = [[[NSString alloc] initWithData: response data encoding: NSUTF8 string encoding] autorelage];  

(NB: You have to check the error response, I left it for clarity)

In addition to this, ideally (because in my example I have synchronous Use method) It should run on a background thread ... but I have found it easier to run and to understand the background thread manually by using "performSelectorInBackground:", as I use the async methods Did the Keep in mind, if you do this then you have to build your own release pool ... but these are the two lines, and it is super easy

The lack thereof, it is possible to end the process. .. You have to run it on a different thread, and kill the thread if it is too long ... but in reality, NSMutableURLRequest is not so bad, and it already gives you the scheduling options that you are looking for Are there.

Thread Programming Guide: Talks about killing threads ... and tells you (indirectly) how to do it ... but if you just kill the thread, then you almost < Em> some leak are guaranteed.


Comments