OpenNETCF.Stopwatch ->只改变刻度,不改变已过去的时间

发布于 2024-08-27 09:53:24 字数 964 浏览 3 评论 0原文

我一直在试图追踪一个我认为与线程相关的错误,但我认为我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

郁金香雨 2024-09-03 09:53:24

是的,这似乎是一个错误,特别是在 Stopwatch.cs 的第 136 行中。

它当前显示为:

smFreqInTicks = (MILLIS_IN_TICKS * 1000) / freq;

它应该显示为:

smFreqInTicks = (MILLIS_IN_TICKS * 1000d) / freq;

现在 smFreqInTicks 最终始终为零,这会杀死您正在查看的值。

Yep, it appears to be a bug, specifically in Stopwatch.cs, line 136.

It currently reads:

smFreqInTicks = (MILLIS_IN_TICKS * 1000) / freq;

it should read:

smFreqInTicks = (MILLIS_IN_TICKS * 1000d) / freq;

Right now smFreqInTicks ends up being always zero, which kills the values you're looking at.

静待花开 2024-09-03 09:53:24

为什么不使用 Compact Framework 本身的版本?从版本 3.5 开始,它位于那里...

Why not use the version in the Compact Framework itself? It's in there from version 3.5 onwards...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文