简体   繁体   English

如何调用 function 但不要等待完成 - ASP.NET

[英]How to invoke a function but don't wait to finish - ASP.NET

I got one page where i do some file manipulation, and when file is done, i need to upload to amazon s3.我在一页上进行了一些文件操作,文件完成后,我需要上传到 amazon s3。 Sometimes file can be large, so user on submit need to wait too much.有时文件可能很大,所以提交的用户需要等待太多。 How can i make something like我怎样才能做出类似的东西

  1. File manipulation文件操作
  2. When is done, i send file name parameters to some function完成后,我将文件名参数发送到一些 function
  3. I don't need to wait for that function, i want to use Response.Redirect before uploading is done.我不需要等待那个 function,我想在上传完成之前使用 Response.Redirect。

Easiest way to do this:最简单的方法:

ThreadPool.QueueUserWorkItem(YourUploadMethod);

There is some comment below arguing with this, so I wrote this:下面有一些评论与此争论,所以我写了这个:

    protected void Page_Load(object sender, EventArgs e)
    {
        ThreadPool.QueueUserWorkItem(YourUploadMethod);

        Response.Redirect("http://google.com");
    }

    public void YourUploadMethod(object state)
    {
        Thread.Sleep(7000);
    }// breakpoint: I was redirected to google and then debugger stopped me here

You need to start the method on a different thread - since you don't have to wait for the function to return, you don't need a callback.您需要在不同的线程上启动该方法 - 因为您不必等待 function 返回,所以不需要回调。

See the Thread class and the Task class.请参阅Thread class 和Task class。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET 内核 - 无需等待即可发送 email - ASP.NET Core - Send email without wait 在 Flutter 中呈现小部件之前,如何等待异步 function 完成执行 - How do I wait for an async function to finish executing before rendering a widget in Flutter 如何在继续之前等待 getDownloadURL 完成? - How to wait for getDownloadURL to finish before proceeding? 无法在 Asp.net 核心应用程序中连接到 RDS - Can't connect to RDS in Asp.net core application 无法使用 OIDC 将 ASP.NET MVC 连接到 Azure AD - Can't connect ASP.NET MVC to Azure AD with OIDC 等待 function 在另一个 Lambda 中完成使用 AWS Lambda - Wait for function to finish using AWS Lambda inside another Lambda 如何在执行任务之前等待多个 firebase 查询完成? - How to wait for multiple firebase queries to finish before executing a task? ASP.NET AWS 中托管的 Core 6 应用程序 Lambda function URL 处理程序 - ASP.NET Core 6 app hosted in AWS Lambda function URL Handler 为什么我的 ASP.NET Core 2 方法不能返回 TwiML? - Why can't my ASP.NET Core 2 method return TwiML? Azure 逻辑应用程序无法使用 ASP.Net 以编程方式构建和/或条件 SDK - Azure Logic Apps can't programmatically build And / Or Condition using ASP.Net SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM