[英]System.Threading.Thread is not supported in Windows 8 Store app
Windows 8 Store app does not support Thread anymore: Windows 8商店应用不再支持线程:
I create a thread in class library: 我在类库中创建一个线程:
protected static Thread m_thread = null;
Then in one of the functions: 然后在其中一个功能:
m_thread = new Thread(new ParameterizedThreadStart(RunDetection));
m_thread.Start(Something);
I also need to abort the function: 我还需要中止该功能:
m_thread.Abort();
How can I do this in a WIN8 store app? 如何在WIN8商店应用中执行此操作?
You can run your thread procedure on the threadpool. 您可以在线程池上运行线程过程。
Aborting a thread has never been a viable option, as it could hang your entire process (abandoned lock, inconsistent global state). 中止一个线程从来就不是一个可行的选择,因为它可能会挂起你的整个过程(被抛弃的锁定,不一致的全局状态)。
Creating threads manually usually is a bad practice. 手动创建线程通常是一种不好的做法。 You should really deeply understand multithreading to gain advantage.
你应该真正深入了解多线程以获得优势。 Consider to use ThreadPool :
考虑使用ThreadPool :
ThreadPool.QueueUserWorkItem(_ => { RunDetection(); });
Also, use asynchronous methods whenever is possible. 此外,尽可能使用异步方法。 Ie
SomeActionAsync
, BeginSomeAction
, etc. If class doesn't implement asynchronous methods, than use ThreadPool
for running synchronous methods. 即
SomeActionAsync
, BeginSomeAction
等。如果类没有实现异步方法,那么使用ThreadPool
来运行同步方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.