c# - 如何调用函数但不等待完成 - ASP.NET

标签 c# asp.net amazon-s3 cron

我在一个页面上进行了一些文件操作,当文件完成后,我需要上传到 amazon s3。有时文件可能很大,所以提交的用户需要等待太多。我怎样才能做出类似的东西

  1. 文件操作
  2. 完成后,我将文件名参数发送给某个函数
  3. 我不需要等待那个函数,我想在上传完成之前使用 Response.Redirect。

最佳答案

最简单的方法:

ThreadPool.QueueUserWorkItem(YourUploadMethod);

下面有一些评论反对这个,所以我写了这个:

    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

关于c# - 如何调用函数但不等待完成 - ASP.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10056981/

相关文章:

c# - 将 cookie 添加到 Request.Cookies 集合

amazon-web-services - Pyspark AWS凭证

c# - 带参数类型的转换

c# - 如何阻止 ASP.NET Web API 隐式解释 HTTP 方法?

asp.net - 我们可以在 ASP.Net WEB API 中使用存储库模式和工作单元吗?

amazon-web-services - 无法使用 Hadoop 访问 S3 存储桶

amazon-web-services - 如何读取雅典娜中的转义字符

c# - 如何防止弹出表单从父级获取焦点

c# - 从托管代码访问 GetConsoleHistoryInfo()

c# - 使用 Web API 的 ASP.Net Core 路由