【发布时间】:2014-04-03 15:37:54
【问题描述】:
因此,作为作业的一部分,我试图粗略计算在使用 CSharp 的 ASP.NET Web 表单项目中审查和完成事务所花费的时间。
在我的 ASPX 页面中,我显示了购物车中对象的详细信息。
还有一个按钮可以确认结帐并完成结帐。
我需要计算的是从页面加载到结帐被确认的时间。
这里有两个事件:page_load 和 checkoutbutton_click
所以在文件后面的代码中我是
public partial class CheckoutReview : System.Web.UI.Page
{
public Stopwatch sw = new Stopwatch();
protected void Page_Load(object sender, EventArgs e)
{
sw.Start();
//... code
}
protected void checkoutbutton_click(object sender, EventArgs e)
{
//...code
sw.Stop();
// in the database i am then storing the elapsedMilliSeconds of the stopwatch
}
但问题是,使用此代码,经过的时间始终保持为 0。
如果我将相同的秒表放在checkoutbutton_click() 中,stopwatch 工作正常。
有人可以解释一下我在这里做错了什么吗?
【问题讨论】: