我在新線程中上傳文件,但看起來像服務器正在同一主線程中。 (使用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