From: alfa on
I have set pause to microsecund. I have Microsoft Development Environment
2002 (ver.7.0.9466) and .NET Framework 1.0 (ver 1.0.3705) and
Stopwatch stopWatch = new Stopwatch(); don't work

How can I do it.


From: PvdG42 on

"alfa" <alfa(a)alfa.hr> wrote in message
news:hjnnuq$ppt$1(a)localhost.localdomain...
> I have set pause to microsecund. I have Microsoft Development Environment
> 2002 (ver.7.0.9466) and .NET Framework 1.0 (ver 1.0.3705) and
> Stopwatch stopWatch = new Stopwatch(); don't work
>
> How can I do it.
>

What does "don't work" mean?
Post the exact error message you got and describe when the error occurred
(compile time? run time?)

A quick look in MSDN:

http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx

indicates the class originated in .NET v2.0, indicating your version did not
include the class.


From: Peter Duniho on
alfa wrote:
> I have set pause to microsecund. I have Microsoft Development Environment
> 2002 (ver.7.0.9466) and .NET Framework 1.0 (ver 1.0.3705) and
> Stopwatch stopWatch = new Stopwatch(); don't work
>
> How can I do it.

You can't. Windows is not a real-time operating system, and there is no
effectively way to guarantee exactly a microsecond delay.

And please don't cross-post so broadly. There's no reason to include
non-English-language newsgroups if you're posting your question in English.

Pete
From: Armin Zingler on
alfa schrieb:
> I have set pause to microsecund.

How did you set the pause?


There is no guarantee that you can make a pause of exactly
a ceratin period of time because, in a multitasking environment,
as an application programmer, your job can be interrupted
by other threads running in the system.

> I have Microsoft Development Environment
> 2002 (ver.7.0.9466) and .NET Framework 1.0 (ver 1.0.3705) and
> Stopwatch stopWatch = new Stopwatch(); don't work
>
> How can I do it.

The StopWatch class is new in Framework 2.0. You need Visual Studio 2005
or newer to use Framework 2.0.

In Visual Studio 2002, you can call API functions to measure the time
like the StopWatch class does. You can look for QueryPerformanceCounter
and QueryPerformanceFrequency at http://pinvoke.net

If a lower resolution is acceptable, you can use Environment.TickCount
http://msdn.microsoft.com/en-us/library/system.environment.tickcount.aspx




--
Armin
From: Arne Vajhøj on
On 26-01-2010 16:48, alfa wrote:
> I have set pause to microsecund. I have Microsoft Development Environment
> 2002 (ver.7.0.9466) and .NET Framework 1.0 (ver 1.0.3705) and
> Stopwatch stopWatch = new Stopwatch(); don't work

Your question is not very clear. But I will assume that you want to
pause for a number of microseconds.

The standard Thread.Sleep only takes milliseconds not microseconds.
But Socket.Select takes microseconds.

You should note that both have a semantic as "sleep minimum X" not
"sleep X".

When you go to sleep then other processes/threads start running. And
they may continue for a while after the sleeping period has expired.
The more busy the system is the longer the actual sleeping period will
be.

Furthermore there are some overhead and for very small sleep times
the overhead becomes significant.

The specifics will depend a lot on the computer you are using.

Here are some results from a randomly picked computer (mine !):

USleep 10 microseconds, overhead factor=97,703125
USleep 50 microseconds, overhead factor=19,53125
USleep 100 microseconds, overhead factor=9,765625
USleep 500 microseconds, overhead factor=1,953125
USleep 1000 microseconds, overhead factor=1,953125
Sleep 1 milliseconds, overhead factor=1,953125
Sleep 5 milliseconds, overhead factor=1,171875
Sleep 10 milliseconds, overhead factor=1,0625
Sleep 50 milliseconds, overhead factor=1,015625
Sleep 100 milliseconds, overhead factor=1,015625
Sleep 500 milliseconds, overhead factor=1
Sleep 1000 milliseconds, overhead factor=1

(program attached below)

The short version is that Sleep(1 millisecond) actually takes
2 milliseconds at average, but that USleep(10 microseconds)
actually takes 1000 microseconds at average.

You will have to evaluate what is useful for you.

Arne

PS: VS 2002 / .NET 1.0 is extremely old - upgrade is overdue !

====================================

using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Threading;

namespace E
{
public static class Util
{
private static Socket s;
static Util()
{
s = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
s.Bind(new IPEndPoint(IPAddress.Any, 12345));
}
public static void USleep(int us)
{
IList sl = new ArrayList();
sl.Add(s);
Socket.Select(sl, null, null, us);
}
}
public class Program
{
public static void TestUSleep(int us)
{
DateTime t1 = DateTime.Now;
for(int i = 0; i < 1000000/us; i++)
{
Util.USleep(us);
}
DateTime t2 = DateTime.Now;
Console.WriteLine("USleep " + us + " microseconds, overhead
factor=" + (t2 - t1).TotalSeconds);
}
public static void TestSleep(int ms)
{
DateTime t1 = DateTime.Now;
for(int i = 0; i < 1000/ms; i++)
{
Thread.Sleep(ms);
}
DateTime t2 = DateTime.Now;
Console.WriteLine("Sleep " + ms + " milliseconds, overhead
factor=" + (t2 - t1).TotalSeconds);
}
public static void Main(string[] args)
{
TestUSleep(10);
TestUSleep(50);
TestUSleep(100);
TestUSleep(500);
TestUSleep(1000);
TestSleep(1);
TestSleep(5);
TestSleep(10);
TestSleep(50);
TestSleep(100);
TestSleep(500);
TestSleep(1000);
Console.ReadKey();
}
}
}