如何在Windows Phone 8.1中创建线程 [英] How to create a Thread in windows phone 8.1
问题描述
嗨,我试图在Windows Phone 8.1中创建线程,但没有成功.
Hi, I've tried to create a Thread in windows phone 8.1 without success.
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屋!