在一个工作线程启动异步任务 [英] Start Async Task within a worker thread
问题描述
我有两个问题:
- 我们可以启动/在worker线程执行异步任务?
- 如果是的,在preExecute方法
()
,onProgressUpdate(进展...)
和onPostExecute(结果)
在UI线程调用?
- Can we start/execute an Async Task within a worker thread?
- If yes, the methods
onPreExecute()
,onProgressUpdate(Progress...)
andonPostExecute(Result)
are invoked on the UI thread?
我想知道,因为我有一个工作线程运行的TCP连接,并接收到数据包时,我要开始一个新的线程,使这个数据包的解析,之后刷新UI线程上的一些数据结构。
I wanna know that because I have a TCP connection running on a worker thread and when a packet is received I wanna start a new thread to make the parse of this packet and after that refresh some data structures on the UI thread.
在此先感谢!
推荐答案
的任务实例必须在UI线程上创建,以及
"The task instance must be created on the UI thread.", and
执行(参数...)必须在UI线程上被调用。
"execute(Params...) must be invoked on the UI thread."
因此,我认为回答你的第一个问题是没有。至于第二个,这些方法都在UI线程上调用,但它是一个有点无实际意义。
So I think the answer to your first question is "no". As far as the second, those methods are all invoked on the UI thread, but it's a bit moot.
编辑:我不知道,如果这些是绝对的限制,或强烈的建议,但在这两种情况下,我建议你跟了上去。
I'm not sure if those are absolute restrictions, or strong suggestions, but in both cases, I'd recommend following them.
这篇关于在一个工作线程启动异步任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!