now.ticks不起作用 [英] now.ticks does not work

查看:82
本文介绍了now.ticks不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将它放在一个填充列表框的按钮后面。

因为你会看到时间现在然后是0或填写????????????? >
按下按钮。


有没有办法确定实际经过的时间?


谢谢,Willie


Dim T As Double


T = Now.Ticks


System.Threading.Thread.Sleep (3)


T = Now.Ticks - T


ListBox1.Items.Insert(0,T.ToString(" 0000000000000000" ))

解决方案

" Willie jan" <未***** @ unkown.com> schrieb

将它放在一个填充列表框的按钮后面。
因为你会看到时间现在然后是0或填写????????????按下按钮。

有没有办法确定实际经过的时间?

谢谢,威利

Dim T As Double


Dim t as long


蜱虫很长,而不是两倍。

T = Now.Ticks

System.Threading.Thread.Sleep(3)

T = Now.Ticks - T

ListBox1.Items.Insert(0,T.ToString (0000000000000000))



Now.Ticks的*单位*为100纳秒。

*分辨率*为AFAIR 0.01秒。


睡眠时间超过0.01秒,你会看到差异。


更高分辨率:环境。吸盘。

甚至更高的分辨率:高性能计数器。 (参见

QueryPerformanceCounter和QueryPerformanceFrequency API函数)


Armin


< blockquote> 2005年8月17日星期三15:41:31 +0200,Willie jan写道:

将它放在一个填充列表框的按钮后面。
你会看到时间是现在然后是0或者通过按下按钮填充???????????


有没有办法确定实际经过的时间?

谢谢,Willie

Dim T As Double

T = Now.Ticks

System.Threading.Thread。睡觉(3)

T = Now.Ticks - T

ListBox1.Items.Insert(0,T.ToString(" 0000000000000000"))




不确定你的代码有什么问题,但是这就是我要做的事情:


Dim T as DateTime


T =现在


System.Threading.Thread.Sleep(3)


Dim D作为TimeSpan


D = Now.Subtract(T )


ListBox1.Items.Insert(0,D.ToString())


Willie,

正如其他人建议的那样,你应该使用Long或DateTime来存储T.


DateTime有一个分辨率在100纳秒的时候,它的进动可能会有所变化,但它的分辨率是基于100纳秒的单位,它的分辨率或者b $ b精度是基于系统计时器(可能当然是.01

秒)


QueryPerformanceCounter的分辨率为纳秒或更小(它的

岁差是QueryPerformanceFrequency值)。它基于一个

高分辨率性能计数器,据我所知,这是一些特殊的硬件

商品计数器......


Tickcount的分辨率为微秒。


有一篇MSDN杂志文章讨论了代码的时序块,

但是我有麻烦找到它,它可能是下面的第三个链接

,但它感觉不对...


使用QueryPerformanceCounter来计算时间码在VB.NET中:
http ://support.microsoft.com/default...b; zh-CN; 306978

不确定以下内容是否有帮助:


比较.NET Framework类库中的Timer类
http://msdn.microsoft.com/msdnmag/is...T/default.aspx


为Windows实施持续更新的High_Resolution时间提供程序
http://msdn.microsoft.com/msdnmag/is...r/default.aspx

我通常使用QueryPerformanceCounter作为其使用的单位

性能计数器:


类似于:


声明函数QueryPerformanceCounter Lib" Kernel32" (ByRef counter

As Long)As Boolean

声明函数QueryPerformanceFrequency Lib" Kernel32" (ByRef

频率如长)作为布尔值

''设定一些时间var

昏暗的开始,结束,频率为长

QueryPerformanceFrequency(频率)

QueryPerformanceCounter(开始)

''工作


QueryPerformanceCounter(完成) )

昏暗时间As TimeSpan = TimeSpan.FromSeconds((完成 - 开始)/

频率)


或者你可以使用DateTime:


''设置一些时间var

昏暗开始,完成As DateTime

start = DateTime.Now


''工作


finish = DateTime.Now

昏暗时间As TimeSpan = finish.Subtract(start)


第三种选择是使用Ticks


''设置一些时间var

昏暗的开始,完成整数

start = Environment.TickCount


''工作


''设置第二次变量和comapre得到结果

finish = Environment.TickCount

昏暗时间As TimeSpan = TimeSpan.FromMilliseconds(完成 - 开始)


我的理解是QueryPerformanceCounter通常会更高

分辨率然后是Environment.TickCount,但QueryPerformanceCounter可能没有
不可用。


VB.NET 2005(又名Whidbey,到期在2005年晚些时候)通过

简化选择,提供一个System.Diagnostics.Stopwatch类,它将自动地在QueryPerformanceCounter& Environment.TickCount ...

http:// lab .msdn.microsoft.com / vs2005 /
http://msdn2.microsoft.com/library/ebf7z0sw.aspx

希望这有帮助

Jay

" Willie jan" <未***** @ unkown.com>在消息中写道

news:43 *********************** @ news.euronet.nl ...

|把它放在一个填充列表框的按钮后面。

|因为你会看到时间现在然后是0或填写????????????

|按下按钮。

|

|有没有办法确定实际经过的时间?

|

|谢谢,威利

|

| Dim T As Double

|

| T = Now.Ticks

|

| System.Threading.Thread.Sleep(3)

|

| T = Now.Ticks - T

|

| ListBox1.Items.Insert(0,T.ToString(" 0000000000000000"))

|

|


place this behind a button that fills a listbox.
as you will see the time is now and then 0 or filled in????????????
by hitting the button.

is there a way to determine the real elapsed time?

thanks, Willie

Dim T As Double

T = Now.Ticks

System.Threading.Thread.Sleep(3)

T = Now.Ticks - T

ListBox1.Items.Insert(0, T.ToString("0000000000000000"))

解决方案

"Willie jan" <un*****@unkown.com> schrieb

place this behind a button that fills a listbox.
as you will see the time is now and then 0 or filled in????????????
by hitting the button.

is there a way to determine the real elapsed time?

thanks, Willie

Dim T As Double
Dim t as long

Ticks is long, not double.
T = Now.Ticks

System.Threading.Thread.Sleep(3)

T = Now.Ticks - T

ListBox1.Items.Insert(0, T.ToString("0000000000000000"))


The *unit* of Now.Ticks is 100 nano seconds.
The *resolution* is AFAIR 0.01 seconds.

Sleep longer than 0.01 seconds and you''ll see a difference.

Higher resolution: Environment.Tickcount.
Even higher resolution: High performance counter. (see
QueryPerformanceCounter and QueryPerformanceFrequency API functions)


Armin


On Wed, 17 Aug 2005 15:41:31 +0200, Willie jan wrote:

place this behind a button that fills a listbox.
as you will see the time is now and then 0 or filled in????????????
by hitting the button.

is there a way to determine the real elapsed time?

thanks, Willie

Dim T As Double

T = Now.Ticks

System.Threading.Thread.Sleep(3)

T = Now.Ticks - T

ListBox1.Items.Insert(0, T.ToString("0000000000000000"))



Not sure what''s wrong with your code, but here''s what I would have done:

Dim T as DateTime

T = Now

System.Threading.Thread.Sleep(3)

Dim D as TimeSpan

D = Now.Subtract(T)

ListBox1.Items.Insert(0, D.ToString())


Willie,
As the others suggest, you should use Long or DateTime to store T.

DateTime has a "resolution" of 100-nanoseconds, its precession can vary, in
that although it is based on units of 100-nanosecond its resolution or
precision is based on the system timer (which may be as course as .01
seconds)

QueryPerformanceCounter has a resolution of nanoseconds or smaller (its
precession is the QueryPerformanceFrequency value). Its based on a
"high-resolution performance counter", which I understand is a special hard
ware counter on some CPUs...

Tickcount has a resolution of microseconds.

There is an MSDN Magazine article that discusses timing blocks of code,
however I am having trouble finding it right now, it may be the third link
below, however it doesn''t feel right...

Use QueryPerformanceCounter to Time code in VB.NET:
http://support.microsoft.com/default...b;en-us;306978

Not sure if the following will help or not:

Comparing the Timer Classes in the .NET Framework Class Library
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Implement a Continuously Updating, High_Resolution Time Provider for Windows
http://msdn.microsoft.com/msdnmag/is...r/default.aspx
I normally use QueryPerformanceCounter as its in the units used by
Performance Counters:

Something like:

Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef counter
As Long) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef
frequency As Long) As Boolean
'' set some time var
Dim start, finish, frequency As Long
QueryPerformanceFrequency(frequency)
QueryPerformanceCounter(start)

'' work

QueryPerformanceCounter(finish)
Dim time As TimeSpan = TimeSpan.FromSeconds((finish - start) /
frequency)

Alternatively you can use DateTime:

'' set some time var
Dim start, finish As DateTime
start = DateTime.Now

'' work

finish = DateTime.Now
Dim time As TimeSpan = finish.Subtract(start)

A third alternative would be to use "Ticks"

'' set some time var
Dim start, finish As Integer
start = Environment.TickCount

'' work

'' set second time var and comapre to get result
finish = Environment.TickCount
Dim time As TimeSpan = TimeSpan.FromMilliseconds(finish - start)

My understanding is that QueryPerformanceCounter will normally be a higher
resolution then Environment.TickCount, however QueryPerformanceCounter may
not be available.

VB.NET 2005 (aka Whidbey, due out later in 2005) simplifies the choice by
providing a System.Diagnostics.Stopwatch class that will automatically
choose between QueryPerformanceCounter & Environment.TickCount...

http://lab.msdn.microsoft.com/vs2005/

http://msdn2.microsoft.com/library/ebf7z0sw.aspx

Hope this helps
Jay
"Willie jan" <un*****@unkown.com> wrote in message
news:43***********************@news.euronet.nl...
| place this behind a button that fills a listbox.
| as you will see the time is now and then 0 or filled in????????????
| by hitting the button.
|
| is there a way to determine the real elapsed time?
|
| thanks, Willie
|
| Dim T As Double
|
| T = Now.Ticks
|
| System.Threading.Thread.Sleep(3)
|
| T = Now.Ticks - T
|
| ListBox1.Items.Insert(0, T.ToString("0000000000000000"))
|
|


这篇关于now.ticks不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆