I have an app with 2 threads (now), but it seems that function Thread.Sleep() doesn't work very good. It sleeps threads but it takes much more time (for example- I want to sleep it for 5ms and it sleeps for 0,3s or more). Here is code:
int vlakien = 2;
Thread[] vlakna;
vlakna = new Thread[vlakien];
for (int i = 0; i < vlakien; i++)
{ try { vlakna[i] = new Thread(new ThreadStart(utok)); vlakna[i].Start(); } }
private void utok()
{
//some code
Thread.Sleep(5);
//some code
}
Also I tried to sleep it with Stopwatch in the function utok and it also takes more time:
Stopwatch SW = new Stopwatch(); SW.Start();
while(SW.ElapsedMilliseconds < 5000) ;
Please help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…