异步CTP MVC4和工作流程 [英] Async ctp MVC4 and workflows
问题描述
我有低于code它调用的工作流。我想知道如果我可以改变控制器使用异步CTP是异步的。
I have the below code which calls a workflow. I am wondering if I can changed the controller to be asynchronous using the async ctp.
public ActionResult Index()
{
var input = new Dictionary<string, object>();
input["ViewData"] = this.ViewData;
var userState = "BeginInvoke example";
var invoker = new WorkflowInvoker(HelloMvcDefinition);
Task workflowTask = Task.Factory.FromAsync<IDictionary<string, object>>(
invoker.BeginInvoke(input, WorkflowCompletedCallback, userState),
invoker.EndInvoke);
workflowTask.Wait();
return View();
}
我已经试过,但我似乎无法得到它的工作:
I have tried this but I cannot seem to get it to work:
public async Task<ActionResult> Index()
{
var input = new Dictionary<string, object>();
input["ViewData"] = this.ViewData;
var userState = "BeginInvoke example";
var invoker = new WorkflowInvoker(HelloMvcDefinition);
Task workflowTask = Task.Factory.FromAsync<IDictionary<string, object>>(
invoker.BeginInvoke(input, WorkflowCompletedCallback, userState),
invoker.EndInvoke);
await workflowTask;
return View();
}
不幸的观点似乎并没有工作。什么我做错了任何想法?
Unfortunately the view does not seem to work. Any ideas on what I am doing wrong?
编辑
服用后通知我已经改变了方法,这种
EDIT After taking advice I have changed the method to this
public class HelloController : AsyncController
{
private static readonly HelloWorkflow HelloMvcDefinition = new HelloWorkflow();
public Task<ViewResult> Index()
{
var input = new Dictionary<string, object>();
input["ViewData"] = ViewData;
const string userState = "BeginInvoke example";
var invoker = new WorkflowInvoker(HelloMvcDefinition);
return Task.Factory.FromAsync<IDictionary<string, object>>(
invoker.BeginInvoke(input, WorkflowCompletedCallback, userState),
invoker.EndInvoke).ContinueWith(t => View());
}
static void WorkflowCompletedCallback(IAsyncResult result)
{
}
}
的正常工作,所以这个问题一定要我如何使用异步关键字。
Which works fine so the problem must be how I am using the async keyword.
感谢
推荐答案
我们可以使用TAP模式来调用Windows工作流如下 -
(详细内容在我的博客文章中提到的http://tweetycodingxp.blogspot.com/2013/06/invoke-workflow-wf-using-task-based.html)
We can use the TAP pattern for invoking windows workflow as follows - (Details are mentioned in my blog post http://tweetycodingxp.blogspot.com/2013/06/invoke-workflow-wf-using-task-based.html)
public async Task<ActionResult> Index(string id)
{
var wfInputArgs = new Dictionary<string, object>
{
...
};
var wfOutputArgs = await Task<IDictionary<string, object>>.Factory.StartNew(
() => WorkflowInvoker.Invoke(new MyWorkflow(), wfInputArgs));
var result = wfOutputArgs["Output1"] as IEnumerable<Class1>;
...
return View(model);
}
这篇关于异步CTP MVC4和工作流程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!