Windows 8 Store app does not support Thread anymore:
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?
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.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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.