System.Threading.Thread.Sleep C# (CSharp) Method

Sleep() public static method

public static Sleep ( int millisecondsTimeout ) : void
millisecondsTimeout int
return void
        public static void Sleep(int millisecondsTimeout)
        {
        }

Same methods

Thread::Sleep ( System timeout ) : void

Usage Example

Example #1
0
    private static void Transfer(Socket socket)
    {
        int txDataLen = random.Next(maxDataLen);
        int rxDataLen;

        TransferHeaders(socket, txDataLen, out rxDataLen);
        // System.Console.WriteLine ("txDataLen="+txDataLen+" rxDataLen="+rxDataLen);
        socket.Blocking = false;
        socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
        // Disable the Nagle algorithm for send coalescing.
        int txPos = 0;
        int rxPos = 0;

        while (txPos < txDataLen || rxPos < rxDataLen)
        {
            // System.Console.WriteLine ("txPos="+txPos+"/"+txDataLen+" rxPos="+rxPos+"/"+rxDataLen);
            int txReqLen = Math.Min(txDataLen - txPos, 1 + random.Next(maxBlockLen));
            int txTrLen  = Send(socket, txReqLen);
            txPos += txTrLen;
            int rxReqLen = Math.Min(rxDataLen - rxPos, maxBlockLen);
            int rxTrLen  = Receive(socket, rxReqLen);
            rxPos += rxTrLen;
            if (random.Next(1000) == 0)
            {
                Thread.Sleep(50);
            }
            else if ((txTrLen < txReqLen && rxTrLen < rxReqLen) || random.Next(50) == 0)
            {
                Thread.Sleep(1);
            }
        }
        socket.Shutdown(SocketShutdown.Both);
    }
All Usage Examples Of System.Threading.Thread::Sleep