Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在执行异步方法时显示带有动画的页面,然后重定向_C#_Asp.net Core_Asp.net Core 2.0 - Fatal编程技术网

C# 在执行异步方法时显示带有动画的页面,然后重定向

C# 在执行异步方法时显示带有动画的页面,然后重定向,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

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
    // from page with animation to
    // to an action
}
如何从异步方法重定向到操作?当
等待DoSomething()
处理数据时,动画页面必须始终显示。

基本上,您不能

由于您没有等待
DoWork
方法返回的
Task
,因此在
DoWork
完成执行之前,HTTP事务已经结束

切换到JavaScript中的客户端解决方案:

  • 开始运行动画
  • 使用XHR调用长时间运行的操作
  • HXR完成后停止动画
  • 查看此线程的示例:。

    基本上,您不能

    由于您没有等待
    DoWork
    方法返回的
    Task
    ,因此在
    DoWork
    完成执行之前,HTTP事务已经结束

    切换到JavaScript中的客户端解决方案:

  • 开始运行动画
  • 使用XHR调用长时间运行的操作
  • HXR完成后停止动画

  • 请参阅此线程以获取示例:。

    您需要小心使用您的方法。不是等待
    任务
    和执行
    异步无效
    只是在问问题。我建议您阅读一些关于异步编程的知识。您需要小心使用您的方法。不是等待
    任务
    和执行
    异步无效
    只是在问问题。我建议您阅读一些关于异步编程的内容。