在一个web mvc项目中。异步映像文件保存
我有以下功能我想使异步,因为我保存了许多文件,它有点慢。我是否需要添加到任务列表,并等待所有:
var fs = new FileSaver();
property.FloorPlanPath = fs.SaveFile(propertyRentalForm.FloorPlanFile, "~/uploads/properties/floorplans");
property.FloorPlan2Path = fs.SaveFile(propertyRentalForm.FloorPlan2File, "~/uploads/properties/floorplans");
property.EpcPath = fs.SaveFile(propertyRentalForm.EpcFile, "~/uploads/properties/epc");
public string SaveFile(HttpPostedFileBase file, string uploadPath)
{
if (file == null || file.ContentLength <= 0) return "";
var fileName1 = Path.GetFileName(file.FileName);
if (fileName1 == null) return "";
// clean file name
fileName1 = string.Format("{0}{1}",
Path.GetFileNameWithoutExtension(fileName1).GetAliasTitle(),
Path.GetExtension(fileName1));
var path = Path.Combine(HttpContext.Current.Server.MapPath(uploadPath), fileName1);
file.SaveAs(path);
return fileName1;
}
你为什么不使用'BackgroundWorker'? –
你有代码示例,这是一个mvc应用 – matt
你有Google吗? –