我在新线程中上传文件,但看起来像服务器正在同一主线程中。 (使用ASP.NET MVC)文件上传未在Web服务器的后台线程中运行
本地文件上传需要3秒,但在实时web服务器上,需要20秒完成方法,这仅仅是因为文件上传。 我无法理解它是在后台线程中,为什么它会增加返回时间。
在实时Web服务器我使用IIS 8 以下是代码
string path = string.Empty;
string thumbPath = string.Empty;
HttpContext cont = HttpContext.Current;
string url = HttpContext.Current.Request.Url.Host.ToLower();
Thread t1= new Thread(() =>
{
if (files.Count() > 0 || files != null)
{
foreach (HttpPostedFileBase file in files)
{
if (file != null)
{
string newFileName = System.Guid.NewGuid().ToString("N");
Photo photo = new Photo();
path = UploadFile(cont, file, ad.Id.ToString(), newFileName);
//Create thumbnail
thumbPath = CreateAdThumbNail(cont, file, ad.Id.ToString(), newFileName);
}
}
}
});
t1.IsBackground = true;
t1.Start();
string[] message = new string[2];
message[0] = "true";
message[1] = "http://" + HttpContext.Current.Request.Url.Host.ToLower() + "/Ad/Item/" + "?section=myads";
return Json(message, JsonRequestBehavior.AllowGet);
如果您的上传需要20秒,您会非常接近请求超时,这是30秒。您可能想要通过AJAX查看上传块,例如与plupload。 – LocEngineer