如何在Windows Phone 8.1中创建线程 [英] How to create a Thread in windows phone 8.1

查看:66
本文介绍了如何在Windows Phone 8.1中创建线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

,我试图在Windows Phone 8.1中创建线程,但没有成功.

Hi, I've tried to create a Thread in windows phone 8.1 without success.

在msdn文档中写的都是支持线程的,实际上是行不通的(

Althought in msdn documentation is written that Thread is supported, actually do not works (https://msdn.microsoft.com/en-us/library/274eh01d(v=vs.110).aspx)

所以我无法弄清楚如何创建线程,我想创建一个Syncronization上下文以在单个线程(不是当前线程)上执行异步,而只是实现事件循环的作用

so I can't figureout how can I create a Thread, I want to create a Syncronization context to execute async on a single thread (not current thread), but just to achieve what event loop do

谢谢

我会更具体:

平台是通用应用,所以我的意思是Windows 8.1& Windows Phone 8.1,没有Silverlight ecc.

platform is universal app, so I mean windows 8.1 & windows phone 8.1, no silverlight ecc.

我需要创建一个线程,因为我想创建一个同步上下文来执行一些异步代码,这是一个有关我的意思的示例

I need to create a thread because I want to create a syncronization context to execute some async code, here is an example about what I mean http://blogs.msdn.com/b/pfxteam/archive/2012/01/20/10259049.aspx the difference from this link is I would use a specific thread for all async code instead current thread.

再次感谢

推荐答案

如果您只想异步运行某些代码,请考虑使用

If you just want to run some code asynchronously, look into using Task.Run. It provides a much simpler mechanism than managing threads yourself.

如果要构建通用Windows Phone 8.1应用程序,则不能使用.NET Thread类型.如果需要对执行进行更多控制,则可以使用WinRT ThreadPool .

If you are building an Universal Windows Phone 8.1 app, you can't use the .NET Thread type. If you need more control over the execution, you can use the WinRT ThreadPool.

最后,如果您真的真的需要很多控制,则总是

Finally, if you really really need lots of control, there's always CreateThread if you want to write native code (this has recently been added to the allowed list of APIs for Store Apps, although MSDN isn't updated yet).

这篇关于如何在Windows Phone 8.1中创建线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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