我在一个页面上进行了一些文件操作,当文件完成后,我需要上传到 amazon s3。有时文件可能很大,所以提交的用户需要等待太多。我怎样才能做出类似的东西
- 文件操作
- 完成后,我将文件名参数发送给某个函数
- 我不需要等待那个函数,我想在上传完成之前使用 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/