| Willy Denoyette [MVP] wrote:
| > | I disagree. I suspect it's only a problem for him if it takes a fair
| > | amount of time, eg 10ms. In fact, I suspect that it must be taking
| > | longer than that for it to have been noticed in the first place.
| >
| > Well, it looks like only the OP can answer that question, maybe he did
| > notice something but IMO it has nothing to do with a thread "start
delay",
| > read one of it's other replies that asks about a lock on his thread
| > procedure, IMO he noticed a (variable?) delay when executing the thread
| > proc, but thinks it's due to the thread start delay.
|
| Ironically, the OP has answered the question of what accuracy he wants:
| "Immediately is for me 10, 20ms. Anything above 100 ms second is not
| acceptable."
|
Yes, but that was AFTER I told him his way of measuring was flawed, he never
said what exactly he measured not what he was expecting before that. If you
measure something that normally takes a from ~500 µseconds up to a few 10
milliseconds you shouldn't use a timer with a resolution of 10 - 20 msecs.
| In other words, using DateTime.Now is more than adequate to tell the
| difference between acceptable and unacceptable.
|
| > Anyway there are far better ways to measure such intervals (if you ever
need
| > to), using a timer with a 10-20 msec. resolution to measure possible
| > millisecond or even sub-milliseconds intervals makes no sense, unless
you
| > know that a result of 0 could also mean 15 msecs. and 16 msec. could
also be
| > 30 msec.
|
| And if you need to measure those intervals, I agree. I just don't think
| that such a level of accuracy is called for in this case.
|
Again, he only mentioned his requirements after I asked for, besides, what's
wrong with a higher level of accuracy, does it hurt?.
| > | I certainly agree with that, but I don't think it invalidates the
| > | coarse test of "is this where my problem is" by using DateTime.Now.
For
| > | 1.1 projects, that's considerably simpler than using performance
| > | counters, and is often all that's needed.
| >
| > Who said performance counters? I'm talking about a Win32 API call
| > QueryPerformanceCounter(...),
|
| I couldn't remember the exact name of the API call, but knew it was
| *something* like the above. It's not entirely unreasonable to think
| that a call to "QueryPerformanceCounter" has something to do with
| performance counters

|
Actually, it's a call into Kernel32.dll a system library, it's the same API
is used by the performance counters and now Stopwatch but not the other way
around.
| > all you need is a two PInvoke declarations
| > wrapped in a utility class and you are done, just like Stopwatch does,
| > right?.
|
| So do you have that utility class handy in every piece of code you
| write? Or do you need to always add a reference to a project that
| contains it? I'd rather not do that unless I really need to - and I see
| no evidence for that need in this case.
|
I don't. I have more accurate tools available if really needed, tools that
count the # of CPU instructions executed between two trigger points for
instance, I rarely feel the need to measure such delays though when running
managed code.
However, other people may find such a library of tools usefull, IMO it's one
of the reasons MS has added Stopwatch to the framework, just to prevent
people to re-invent the wheel.
| > Even if you don't wan't to do all this you can :
| >
| > start a utility like (but not restricted to) dbgvw.exe (from
| >
www.sysinternals.com)
| > change your code like this:
| > Debug.WriteLine("start")
| > t.Start();
| > Debug.WriteLine("started")
| > and oeps instant accurate (in terms of whats possible on NT like
systems).
|
| Again though, it's more hassle than using DateTime.Now if accuracy like
| that isn't required.
|
Oh come on, where's the hassle ? Start the debug viewer?
What's the difference between calling
DateTime start = DateTime.Now;
...
Console.WriteLine("{0}", TimeSpan(.....));
vs.
Debug.Write("...")
....
Debug.Write("...")
Agreed, when precision is not an issue, you can do with DateTime.Now, but if
you really need to measure things that will take less than a few hundred
milliseconds there are better ways like Stopwatch in v2 and
QueryPerformanceXXXX in v1.
Willy.