C# 在执行异步方法时显示带有动画的页面,然后重定向
ASP.NET核心2.0C# 在执行异步方法时显示带有动画的页面,然后重定向,c#,asp.net-core,asp.net-core-2.0,C#,Asp.net Core,Asp.net Core 2.0,ASP.NET核心2.0 public IActionResult Processing() { DoWork(); return View(); // returning Processing.cshtml // which contains page with animation } private async void DoWork() { await DoSomething(); // and here I want to redirect
public IActionResult Processing()
{
DoWork();
return View(); // returning Processing.cshtml
// which contains page with animation
}
private async void DoWork()
{
await DoSomething();
// and here I want to redirect
// from page with animation to
// to an action
}
如何从异步方法重定向到操作?当等待DoSomething()
处理数据时,动画页面必须始终显示。基本上,您不能
由于您没有等待DoWork
方法返回的Task
,因此在DoWork
完成执行之前,HTTP事务已经结束
切换到JavaScript中的客户端解决方案:
DoWork
方法返回的Task
,因此在DoWork
完成执行之前,HTTP事务已经结束
切换到JavaScript中的客户端解决方案:
请参阅此线程以获取示例:。您需要小心使用您的方法。不是等待
任务
和执行异步无效
只是在问问题。我建议您阅读一些关于异步编程的知识。您需要小心使用您的方法。不是等待任务
和执行异步无效
只是在问问题。我建议您阅读一些关于异步编程的内容。