Sign in to follow this  
Kryptus

Network Loop Problem

Recommended Posts

Kryptus    100
I am using Visual C# 2005 Beta 2 to make a simple server with a tray icon. The server is in a data loop of mine receiving data from clients but during this time (which is the entire time the program is running) I can't access the tray icon. It appears and has a balloon but if I right click it nothing happens. But as soon as the loop stops the menu appears. How do I get around this problem without compromising my loop?

Share this post


Link to post
Share on other sites
DaBono    1496
If your network loop is using blocking I/O, create a separate thread that contains your data loop. Your current program is probably blocking on listening for network traffic, which means Windows-messages are just waiting in the queue, doing nothing.
If you don't want to burn your hands on multithreading, look into functions like select. That way you can create a loop having the following concept:

while( running )
{
// Listen for Windows messages and handle them
while( PeekMessage( ... ) )
{
case WM_BLABLA:
etc...
}

// See if there is network traffic and handle it
NetworkMessage mess;
while( NetworkTrafficMessage( &mess ) )
{
handleMessage( mess );
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this