Good Morning,
I am getting a bit stuck by ThreadPool. On my IRC bot when it receives a message I want it to raise a new thread with the inbound message to process it.
The way I have achieved this is:
Then on the Processor Routine:
Now this works perfectly until you start saying 'Hello' multiple times. To spot the problem I added in a sleep on the processor thread and also a counter system which displayed in my gui:
Now If i say Hi 10 times the ThreadsActive instantly counts up to 7 then a second later 8 then after 5 seconds starts to countdown very quick stops a 2 for a second and then 0. However only 9 Hi's have been outputted.
So i try again this time saying Hello 20 times The same happens to the queue but this time when it reaches 2 it jumps between 2 and 3 for a few seconds then down to 0. This time only 13 Hi's were outputted.
Just to be sure I had one more counter ThreadHistory:
This time I say Hello 25 times and at the end of all the processing the ThreadHistory counter is at 15
So the more items I queue the more it looses. Does anyone know whats going on here?
Thanks
Max
I am getting a bit stuck by ThreadPool. On my IRC bot when it receives a message I want it to raise a new thread with the inbound message to process it.
The way I have achieved this is:
Code:
Private Sub NewMessage(ByVal message As String) Handles Sock.ReceiveMessage
ThreadPool.QueueUserWorkItem(AddressOf Processor, message)
End SubCode:
Private Sub Processor(byval message as string)
If message.Contains("Hello") Then
Outboud.Enqueue("PRIVMSG #WurmTest :Hi" & vbCr & vbLf)
End If
End SubCode:
Dim ThreadsActive as integer = 0
Private Sub Processor(byval message as string)
ThreadsActive +=1
If message.Contains("Hello") Then
Threading.Thread.Sleep(5000)
Outboud.Enqueue("PRIVMSG #WurmTest :Hi" & vbCr & vbLf)
End If
ThreadsActive -=1
End SubSo i try again this time saying Hello 20 times The same happens to the queue but this time when it reaches 2 it jumps between 2 and 3 for a few seconds then down to 0. This time only 13 Hi's were outputted.
Just to be sure I had one more counter ThreadHistory:
Code:
Dim ThreadsActive as integer = 0
Dim ThreadHistory as integer = 0
Private Sub Processor(byval message as string)
ThreadsActive +=1
ThreadHistory +=1
If message.Contains("Hello") Then
Threading.Thread.Sleep(5000)
Outboud.Enqueue("PRIVMSG #WurmTest :Hi" & vbCr & vbLf)
End If
ThreadsActive -=1
End SubSo the more items I queue the more it looses. Does anyone know whats going on here?
Thanks
Max