简体   繁体   English

Xamarin.Android中的后台执行

[英]Background execution in Xamarin.Android

I want to execute some code in background in my Xamarin.Android app. 我想在我的Xamarin.Android应用程序中在后台执行一些代码。 For example, make a HTTP request and do some actions on server side, get a response and update UI. 例如,发出HTTP请求并在服务器端执行某些操作,获取响应并更新UI。

So, should I really use Android specific components like AsyncTask , IntentService , etc for that? 那么,我真的应该使用AsyncTaskIntentService等特定于Android的组件吗? Can I just run my code in Task.Run ? 我可以在Task.Run运行我的代码吗? Are there useful methods in C#/Mono to achieve my purpose? C#/ Mono中是否有有用的方法来实现我的目的?

You should use the C# model of asynchronous programming , it is used extensively in most Xamarin applications. 您应该使用异步编程C#模型 ,它在大多数Xamarin应用程序中广泛使用。 Basically, your methods return "async Task" objects, which you can then "await" without blocking the UI thread. 基本上,您的方法返回“异步任务”对象,然后您可以“等待”而不会阻止UI线程。

EDIT 编辑

I also found some related information specific to Xamarin . 我还发现了一些特定于Xamarin的相关信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM