如何重新启动/再重复任务? [英] How to restart/reuse a recurring Task?

查看:134
本文介绍了如何重新启动/再重复任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用任务并行库已经实现了一个长期运行的任务。当任务开始时,我抓住几个输入值和集合的快照,然后利用这些信息进行各种操作。如果任何这些值或集合的任务运行时更改,我想有任务完成后立即再次运行。我应该创建一个新的任务或者是有没有办法重用现有的任务?什么是启动第二循环的最佳方式?

I have a long-running Task that I've implemented using the Task Parallel Library. When the Task starts, I grab snapshots of several input values and collections then perform various operations using that information. If any of those values or collections change while the Task is running, I'd like to have the Task run again immediately upon completion. Should I be creating a new Task or is there a way to reuse the existing Task? What's the best way to start the second iteration?

推荐答案

创建一个新的任务。

作为<一个href="http://msdn.microsoft.com/en-us/library/dd270682.aspx">http://msdn.microsoft.com/en-us/library/dd270682.aspx指出,试图重新启动运行或完成不支持任务。这是很少一个好主意,做一些事情,通常会抛出异常,并重新使用一个任务就是其中的一件事情。

As http://msdn.microsoft.com/en-us/library/dd270682.aspx points out, trying to restart a running or completed Task is not supported. It is rarely a good idea to do something that normally throws an exception, and re-using a Task is one of those things.

这篇关于如何重新启动/再重复任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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