如何取消另一个线程中的 xml 解析
我想连接 Web 服务并解析 xml,因为执行需要时间,所以我在一个单独的线程中完成它并向用户显示活动指示器,现在我还想插入取消选项。
因为如果网络连接或解析需要很长时间并且用户想要中止处理,用户将能够执行此操作。
所以我现在的问题是如何取消线程?主要问题是网络连接是一个单独的类,而 xml 解析是另一个类,并且两者都是按顺序执行的,那么我该如何管理它。
如何取消网络连接或者可能正在解析那么我如何中止解析和线程。
谢谢
i want to connect the webservice and parse the xml as it will take time to execute so i done it in a separate thread and show a activity indicator to the user now i also want to insert the cancel option.
Because if the network connection or parsing take long time and user want to abort the processing the user will be able to do this.
so my question is now how can i cancel a thread? the main problem is that the network connection is a separate class and xml parsing is another class and as both are sequentially executing then how can i manage it.
how to cancel network connection or may be it's parsing then how can i abort the parsing and thread.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSURLConnection
返回一个connection
句柄,您可以将cancel
消息发送到该句柄。NSURLConnection
returns aconnection
handle and you can send thecancel
message to that handle.