【发布时间】:2015-02-27 06:06:10
【问题描述】:
我有一个 WCF Rest 服务,它公开了一个 Web 方法,该方法应该启动一个长时间运行的进程,然后立即返回一个表示可用于跟踪任务状态的任务的 id。
[WebGet]
public Task<Guid> LongRunningProcess()
{
var taskId = new Guid();
var task = Task.Factory.StartNew(() =>
{
//Perform long running task
}
task.ContinueWith(task =>
{
//Send a notification to the client that the task has completed.
}
return taskId;
}
我的问题是,这是正确的做法吗?还是有更好更轻量级的方法?
【问题讨论】:
-
您使用的是什么版本的 .NET?
标签: c# wcf rest asynchronous task