Asp.net mvc 如何在ASP.NETMVC中获取方法的开始时间和结束时间?
我的控制器上传方法中有一个方法,可以将上传的图像文件转换为三种不同的大小。我想显示从上传文件到停止转换的方法结束所花费的时间。有人能告诉我怎么做吗Asp.net mvc 如何在ASP.NETMVC中获取方法的开始时间和结束时间?,asp.net-mvc,datetimepicker,Asp.net Mvc,Datetimepicker,我的控制器上传方法中有一个方法,可以将上传的图像文件转换为三种不同的大小。我想显示从上传文件到停止转换的方法结束所花费的时间。有人能告诉我怎么做吗 this is my controller public ActionResult Upload() { //ViewBag.ProcessingTime = DateTime.Now; return View(); } [HttpPost]
this is my controller
public ActionResult Upload()
{
//ViewBag.ProcessingTime = DateTime.Now;
return View();
}
[HttpPost]
public ActionResult Uploading(ImageModel model)
{
if (ModelState.IsValid)
{
Console.WriteLine("time is"+System.DateTime.Now);
string fileName = Guid.NewGuid().ToString() + System.DateTime.Now.ToString("yyyy/MM/dd/hh/mm/ss/fff");
string serverPath = Server.MapPath("~");
string imagesPath = serverPath + "Content\\Images\\";
string thumsise = Path.Combine(imagesPath, "Thumb" + fileName);
string thumbPath = Path.Combine(imagesPath, "Thu" + fileName);
//string thumbPath = imagesPath + "Thumb\\";
string fullPath = Path.Combine(imagesPath, "Full" + fileName);
//string fullPath = imagesPath + "Full\\";
// string Bigpath = imagesPath + "big\\";
string Bigpath = Path.Combine(imagesPath, "big" + fileName);
string Bigpatha = Path.Combine(imagesPath, "biga" + fileName);
string Bigpathb = Path.Combine(imagesPath, "bigb" + fileName);
//string Bigpatha = imagesPath + "biga\\";
//string Bigpathb = imagesPath + "bigb\\";
string Bigpathc = Path.Combine(imagesPath, "bigc" + fileName );
//string Bigpathc = imagesPath + "bigc\\";
//var firstSize = Path.Combine(uploadFolder, "bigsize-" + Path.GetFileName(uploadedFile));
ImageModel.ResizeAndSave(thumsise, fileName, model.ImageUploaded.InputStream, 80, true);
ImageModel.ResizeAndSave(thumbPath, fileName, model.ImageUploaded.InputStream, 100, true);
ImageModel.ResizeAndSave(fullPath, fileName, model.ImageUploaded.InputStream, 500, true);
ImageModel.ResizeAndSave(Bigpath, fileName, model.ImageUploaded.InputStream, 200, true);
ImageModel.ResizeAndSave(Bigpatha, fileName, model.ImageUploaded.InputStream, 250, true);
ImageModel.ResizeAndSave(Bigpathb, fileName, model.ImageUploaded.InputStream, 150, true);
ImageModel.ResizeAndSave(Bigpathc, fileName, model.ImageUploaded.InputStream, 50, true);
Console.WriteLine("Time is " + System.DateTime.Now);
}
Console.WriteLine("Time is "+System.DateTime.Now);
Console.ReadLine();
return View();
}
您必须在您的
模型中添加附加字段
:
public DateTime StartTime { get; set; }
public DateTime OperatingTime { get; set; }
public DateTime EndTime { get; set; }
然后适当地分配每个,即StartTime=DateTime.Now代码>
然后在视图中
:
@Html.DisplayFor(m=>m.StartTime);
附加的
我个人会将上传图像功能包装到一个新方法中,最好是在您的ImageModel
类中。然后您可以执行:model.UploadImage(文件名,imagePath)代码>您必须在您的型号中添加附加字段:
public DateTime StartTime { get; set; }
public DateTime OperatingTime { get; set; }
public DateTime EndTime { get; set; }
然后适当地分配每个,即StartTime=DateTime.Now代码>
然后在视图中
:
@Html.DisplayFor(m=>m.StartTime);
附加的
我个人会将上传图像功能包装到一个新方法中,最好是在您的ImageModel
类中。然后您可以执行:model.UploadImage(文件名,imagePath)代码>使用秒表
var stopwatch = new Stopwatch();
stopwatch.Start();
//whatever you want to time
stopwatch.Stop();
var result1 = string.Format("{0} to run whatever ",
stopwatch.Elapsed.ToString());
Console.WriteLine(result1);
对于多个计时,您可以重置秒表,并执行与第一个类似的更多计时。使用秒表
var stopwatch = new Stopwatch();
stopwatch.Start();
//whatever you want to time
stopwatch.Stop();
var result1 = string.Format("{0} to run whatever ",
stopwatch.Elapsed.ToString());
Console.WriteLine(result1);
对于多个计时,您可以重置秒表并执行与第一个计时类似的更多计时。我必须做什么“{0}才能运行任何东西”此位置{0}将被stopwatch.appeased.ToString()替换。如果您愿意,我将更新以使用您的控制台“{0}运行任何东西”我必须做什么?此位置{0}将被stopwatch.appeased.ToString()替换。如果您愿意,我将更新以使用您的控制台