Thread.Sleep question

F

fniles

I am using VB.NET 2003 and a socket control. As I get quotes, I add the
quote to the arraylist, and I send the quotes to my clients by removing the
message from the arraylist and send it to the client using the socket.
I found that the arraylist got backed up, the queue depth will be 1000 or
bigger. I put a Thread.Sleep(1) outside the While Loop where I remove the
item from the arraylist. Shall I
1. not use Thread. Sleep
Or
2. use Thread.sleep inside the While Loop ?
Shall I use Thread.sleep(0) or Thread.sleep(1) ?
THank you.

Private Quotes As New ArrayList
Private QuotesSync As ArrayList = ArrayList.Synchronized(Quotes)

Sub NewQuote(ByVal Message As String)
QuotesSync.Add(Message)
end sub



Sub ThreadMain()
While QuotesSync.Count > 0
sPacket = QuotesSync(0)
nResult = Socket.Write(sPacket)
QuotesSync.RemoveAt(0)
'---------------------> SHALL I MOVE Thread.Sleep(1) HERE
? ---------------------------
End While
Thread.Sleep(1)
:
End Sub
 
D

Dick Grier

Hi,

You won't find much difference between .Sleep(0) and .Sleep(1). In fact,
depending on the actual problem that you are trying to solve, Sleep may or
may not be needed. If it is, you may need to make the Sleep argument
larger.

At the end-of-the-day, whether you use Sleep inside the loop or not depends
on what you experience. That is... Try it. Sleep outside the loop won't
accomplish anthing useful, IMO.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top