用了幾種執行緒延時的方法,但是編譯后的程式在別的機器上就顯示休眠時間15ms,在自己的機器上就是10ms
int TimeMS =10;
while (SendDataTS_End)
{
while (SendDataTS_End)
{
Stopwatch sw = new Stopwatch();
sw.Start();
//Delay(TimeMS);
//Wait(TimeMS);
System.Threading.Thread.Sleep(TimeMS);
//Thread.SpinWait(TimeMS);
//Thread.Sleep(TimeMS);
sw.Stop();
long totalTime = sw.ElapsedMilliseconds;
}
}
public static void Wait(int ms)
{
DateTime t = DateTime.Now;
bool pd = true;
while (pd)
{
TimeSpan ts = DateTime.Now - t;
if (ts.TotalMilliseconds >= ms)
{
pd = false;
}
}
}
[DllImport("kernel32.dll")]
static extern uint GetTickCount();
static void Delay(uint ms)
{
uint start = GetTickCount();
while (GetTickCount() - start < ms)
{
//Application.DoEvents();
}
}
uj5u.com熱心網友回復:
Threed Sleep 只是保證間隔不小于10,CPU調度,你執行也要時間的。電腦本身就不是實時系統,一般精度在100MSuj5u.com熱心網友回復:
現在是在2臺機器能做到2臺做不到,我想知道因為什么uj5u.com熱心網友回復:
并且做不到的反倒是高處理器大記憶體的
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/186726.html
標籤:C#
上一篇:獲取所有執行緒的名稱
下一篇:c# sqlite難題
