简体   繁体   English

Metro 风格应用程序中的任务

[英]Task in metro style application

I have a question regarding Task in metro style applications (winrt).我有一个关于 Metro 风格应用程序 (winrt) 中的任务的问题。

Thread's are not available (at least since windows 8.1/windows phone 8.1), so to perform asynchronous operations we have to use Task now.线程不可用(至少从 windows 8.1/windows phone 8.1 开始),因此要执行异步操作,我们现在必须使用 Task。

  • When I create Task and call Run doest it create new Thread?当我创建 Task 并调用 Run 时,它会创建新线程吗? If so is there a way to kill/stop that Thread?如果是这样,有没有办法杀死/停止该线程?

  • All Tasks are part of application procces - so when I call Application.Current.Exit() does it stops all Tasks (In case I have not properly stopped/closed/ended them ?) If not Is it possuble?所有任务都是应用程序过程的一部分 - 所以当我调用 Application.Current.Exit() 时它会停止所有任务(如果我没有正确停止/关闭/结束它们?)如果不是它可能吗? In Thread you could set IsBackground property to force to close them whem application was closed.在线程中,您可以设置 IsBackground 属性以在应用程序关闭时强制关闭它们。

  • What happens to Tasks when the application is suspended?当应用程序暂停时,任务会发生什么? And what are guidelines ?什么是指导方针?

Thank you for your help.感谢您的帮助。

When I create Task and call Run does it create new Thread?当我创建 Task 并调用 Run 时,它会创建新的线程吗? If so is there a way to kill/stop that Thread?如果是这样,有没有办法杀死/停止该线程?

It doesn't create a new thread, it will use a thread from the thread pool.它不会创建新线程,而是会使用线程池中的线程。 This is assuming you haven't passed any other TaskScheduler .这是假设您没有通过任何其他TaskScheduler

If so is there a way to kill/stop that Thread?如果是这样,有没有办法杀死/停止该线程?

There is a way to do cooperative cancellation via the CancellationToken and CancellationTokenSource structures.有一种方法可以通过CancellationTokenCancellationTokenSource结构进行协作取消。 There is no way to abort a Task such as with Thread.Abort .没有办法中止Task例如使用Thread.Abort Task != Thread . Task != Thread

so when I call Application.Current.Exit() does it stops all Tasks所以当我调用 Application.Current.Exit() 时它会停止所有任务

Threadpool threads are background by default, they won't prolong the life of your application like a foreground thread.默认情况下,线程池线程是后台线程,它们不会像前台线程那样延长应用程序的生命周期。 You're safe to assume once the application has closed, all threads are terminated.您可以安全地假设,一旦应用程序关闭,所有线程都将终止。

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

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