取消是由Web服务管理的长期任务 [英] Cancel a long task that's managed by a web service

查看:133
本文介绍了取消是由Web服务管理的长期任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个方法Web服务: StartReport(...) IsReportFinished(...) GetReport(...),各家有各家的参数。我也有一个客户端应用(Silverlight的),其会先调用StartReport触发报告的生成,那么它会轮询服务器与IsReportFinished,看是否它的完成,一旦完成,它调用GetReport得到报告。很简单的...结果
StartReport很简单。它首先生成一个唯一的ID,那么它会使用 System.Threading.Tasks.Task.Factory.StartNew()以创建一个新的任务,将生成报告最后返回而任务的唯一ID继续在后台运行。 IsReportFinished只是检查系统看到的唯一ID如果报告已经完成。一旦完成,唯一ID可以用于检索报告。

I have a web service with three methods: StartReport(...), IsReportFinished(...) and GetReport(...), each with various parameters. I also have a client application (Silverlight) which will first call StartReport to trigger the generation of the report, then it will poll the server with IsReportFinished to see if it's done and once done, it calls GetReport to get the report. Very simple...
StartReport is simple. It first generates an unique ID, then it will use System.Threading.Tasks.Task.Factory.StartNew() to create a new task that will generate the report and finally return the unique ID while the task continues to run in the background. IsReportFinished will just check the system for the unique ID to see if the report is done. Once done, the unique ID can be used to retrieve the report.

不过,我需要一种方法来取消任务,这是通过向IsReportFinished一个新的参数来实现。当取消所谓真正的== 如果报告完成,将再次检查。如果报告完成后,没有什么可以取消。否则,它需要取消的任务。结果
如何取消这个任务?

But I need a way to cancel the task, which is implemented by adding a new parameter to IsReportFinished. When called with cancel==true it will again check if the report is done. If the report is finished, there's nothing to cancel. Otherwise, it needs to cancel the task.
How do I cancel this task?

推荐答案

您可以使用取消令牌的取消TPL任务的。这里的<一个href=\"http://stackoverflow.com/questions/4783865/how-do-i-abort-cancel-tpl-tasks/4783890#4783890\">another例如。

You could use a cancellation token to cancel TPL tasks. And here's another example.

这篇关于取消是由Web服务管理的长期任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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