|
-
Mar 23rd, 2006, 12:54 AM
#1
Thread Starter
Member
[RESOLVED] CPU usage in network app (threading?)
Hi guys,
Ok so I'm writing a chat application like thing, which will actually be used in a similar way to MSN Messenger's Whiteboard function.
My problem is that as soon as I start the 'server' program (which also includes a client!) the CPU usage shoots up to 100% and stays there. I think it might be because there is a thread in the background listening for new connections. Is there any way to reduce the CPU usage? (Its slowing down the rest of the app, and don't even think about trying to do anything else!) I've tried reducing the thread priority, but that just seemed to make client's connection take an age.
I can post some source code if you'd like...
Thanks, Mech
-
Mar 23rd, 2006, 03:37 AM
#2
Re: CPU usage in network app (threading?)
how are you listening? are you using a loop?
-
Mar 23rd, 2006, 04:51 AM
#3
Thread Starter
Member
Re: CPU usage in network app (threading?)
Ok, I'm using my network as an attached class, the relevant code is as follows:
VB Code:
Public Sub New(Optional ByVal address As String = "localhost", Optional ByVal port As Integer = 5555)
Try
' Start listening for client requests in the background
LC = New ListenClass(globalAddress, globalPort)
Dim TSThread As Thread
TSThread = New Thread(AddressOf LC.StartListening)
TSThread.Priority = ThreadPriority.BelowNormal
TSThread.Start()
Catch .....
So thats when you create a new instance of the server class (called LC) the LC.StartListening Sub looks like this:
VB Code:
Try
If localListener Is Nothing Then
localListener = New TcpListener(Dns.Resolve(ipHost).AddressList(0), ipPort)
End If
localListener.Start()
tClient = localListener.AcceptTcpClient
RaiseEvent Connected(tClient)
Catch .......
The connected event saves the TCP client information and starts a new Thread to listen for more connections.
Actually, just had a thought... Should I be stopping or disposing of 'TSThread' in the connect code or will that free the memory automatically once a client is connected?
Hope this is not too indigestible! Any help would be greatly appreciated.
-
Apr 5th, 2006, 05:51 AM
#4
Thread Starter
Member
Re: [RESOLVED] CPU usage in network app (threading?)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|