[.net] Looping uses 100% CPU???

Started by
15 comments, last by GameDev.net 18 years, 7 months ago
I would do that do that but last time I tried it, my trayicon didn't work for some reason. It appears but did not do anything when I right clicked. I tried to figure out what was wrong for days so I gave the polling loop a go and the menu worked so I've stuck with it for now. Otherwise I would use asynchronous sockets. Unless of course you know a solution to my problem?
Advertisement
You need to split into two threads, one to handle the UI, and one to sit blocked waiting for data from your socket. The reason your icon didn't work was that your UI thread was blocked waiting for the socket..
Bingo. That makes perfect sense to me. Thanks mate. I'll have to try and implement it. So I create the tray icon as normal and run the socket process on a different thread or the other way around or both on a different thread?
Quote:Original post by Anonymous Poster
You need to split into two threads, one to handle the UI, and one to sit blocked waiting for data from your socket. The reason your icon didn't work was that your UI thread was blocked waiting for the socket..
Or he could just use non-blocking socket or select as was mentioned...
I haven't read all the posts but that is really weird. I have a loop for my Dx9 game and it uses roughly 22% of the CPU all the time I believe. I am using the DirectX9 SDK though to create everything so that may have something to do with it. But even then I though DoEvents should take care of things...?
Quote:Original post by Krisc
I haven't read all the posts but that is really weird. I have a loop for my Dx9 game and it uses roughly 22% of the CPU all the time I believe. I am using the DirectX9 SDK though to create everything so that may have something to do with it. But even then I though DoEvents should take care of things...?


DoEvents wouldn't minimise CPU performance. It just processes Windows messages in the message queue.
There is NO NEED to use threads for this.

Write a function to process the TCPIP traffic.
Then set up an on-idle event, and a timer event(say every 100ms)
Make both these events call the Process TCPIP Traffic function.
Call Sleep(0) on the last line of the on-idle event handler.

The timer event is just there to process IF there have been NO idle event i.e. the machine was busy doing something else.



This topic is closed to new replies.

Advertisement