OpenNETCF.Stopwatch ->只改变刻度,不改变已过去的时间
我一直在试图追踪一个我认为与线程相关的错误,但我认为我使用 OpenNETCF 秒表的方式存在问题。我在我的应用程序中使用 OpenNETCF.IoC ,但为了简单起见,我将以下代码直接移动到视图:
public partial class WorkoutView : SmartPart
{
...
private Stopwatch stopwatch;
public WorkoutView()
{ ...
stopwatch = new Stopwatch();
stopwatch.Reset();
stopwatch.Start();
WorkoutDisplayTimer = new Timer();
WorkoutDisplayTimer.Interval = 500;
WorkoutDisplayTimer.Tick += new EventHandler(WorkoutDisplayTimer_Tick);
WorkoutDisplayTimer.Enabled = true;
}
void WorkoutDisplayTimer_Tick(object sender, EventArgs e)
{ ...
stopwatch.Stop();
lbl.Text = stopwatch.ElapsedTicks.ToString() + "NOT WORKING: " + stopwatch.Elapsed.ToString();
stopwatch.Start();
}
...
}
长话短说,查看调试器中的秒表,唯一更新的值是 ElapsedTicks、mElapsed、mStartPerfCount。其他一切始终为零。这是预期的行为吗?我是否需要调用额外的方法来让秒表计算 Elapsed 结构? (注意:stopwatch.ElapsedMilliseconds 也为零)
I've been trying to track down a bug I thought was thread-related, but I think instead there is an issue with the way I am using OpenNETCF's Stopwatch. I am using OpenNETCF.IoC in my application, but for the sake of simplicity I moved the following code directly into a view:
public partial class WorkoutView : SmartPart
{
...
private Stopwatch stopwatch;
public WorkoutView()
{ ...
stopwatch = new Stopwatch();
stopwatch.Reset();
stopwatch.Start();
WorkoutDisplayTimer = new Timer();
WorkoutDisplayTimer.Interval = 500;
WorkoutDisplayTimer.Tick += new EventHandler(WorkoutDisplayTimer_Tick);
WorkoutDisplayTimer.Enabled = true;
}
void WorkoutDisplayTimer_Tick(object sender, EventArgs e)
{ ...
stopwatch.Stop();
lbl.Text = stopwatch.ElapsedTicks.ToString() + "NOT WORKING: " + stopwatch.Elapsed.ToString();
stopwatch.Start();
}
...
}
Long story short, looking at stopwatch in the debugger, the only values that ever get updated are ElapsedTicks, mElapsed, mStartPerfCount. Everything else is always zero. Is this expected behavior? Do I need to call an additional method to have the stopwatch calculate the Elapsed struct? (Note: stopwatch.ElapsedMilliseconds is also zero)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这似乎是一个错误,特别是在 Stopwatch.cs 的第 136 行中。
它当前显示为:
它应该显示为:
现在 smFreqInTicks 最终始终为零,这会杀死您正在查看的值。
Yep, it appears to be a bug, specifically in Stopwatch.cs, line 136.
It currently reads:
it should read:
Right now smFreqInTicks ends up being always zero, which kills the values you're looking at.
为什么不使用 Compact Framework 本身的版本?从版本 3.5 开始,它位于那里...
Why not use the version in the Compact Framework itself? It's in there from version 3.5 onwards...