MonoDroid活动独立任务队列? [英] MonoDroid Activity Independent Task Queue?

查看:43
本文介绍了MonoDroid活动独立任务队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行许多Web请求的Monodroid应用程序.我正在从活动中提出要求.因此,我需要一个队列来处理我的活动之外的请求.这是为了避免同时发出多个请求.

I have a Monodroid application that does many webrequests. I am making requests from activities. Because of this I have the need for a queue to process my requests outside of my activities. This is to avoid multiple requests being made at the same time.

因为我正在使用ThreadPool.QueueUserWorkItem在另一个线程上发出请求,所以如果用户打开一个活动,开始一个请求,然后返回打开另一个活动,并在另一个请求开始之前使用另一个请求,则在第一个请求完成对webrequests锁的使用之前并不再起作用.

Because I am making my requests on another thread using ThreadPool.QueueUserWorkItem it seems like if a user opens an activity, starts a request then goes back opens another activity and starts another request before the first request has finished the use of webrequests lock up and are no longer functional.

最好的方法是将请求任务与活动之外的回调一起排队,或者有人知道/有类似的例子吗?我认为,需要处理上述情况,在任务完成之前可以关闭/销毁活动.这可能意味着该任务可以被取消或该任务可以运行,但由于该UI不再存在而无法更新UI.

What would the best approach be to queue request tasks with callbacks outside of the activity or does anyone know/have an example of something similar? I think that it would need to deal with cases like explained above where the activity could be closed/destroyed before the task completes. This may mean that the task can be cancelled or the task could run but not update the UI because it no longer exists.

在我的情况下,我发出的请求在不同的函数内执行不同的操作,因此用于更新UI的回调并不总是相同的函数.另外,我用来发出请求的函数具有不同的参数.我不确定这些要点是否会使创建此问题的解决方案更加困难/容易,但是我认为我将需要重新编写很多代码.

In my case the requests that I make are within different functions doing different things so the callbacks to update the UI are not always the same functions. Also the functions that I am using to make the requests have different parameters. I am not sure if these points make it harder/easier to create a solution to this problem but I presume that I will need to rework a lot of my code.

推荐答案

a)使用异步方法发出请求,以免挂起线程池线程.

a) Use asynchronous methods to make your requests so that you're not hanging threadpool threads.

b)增加您请求的域的连接限制.

b) Increase the connection limit for the domains you are requesting from.

ServicePointManager.FindServicePoint(uri).ConnectionLimit=10000;

这篇关于MonoDroid活动独立任务队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆