HandleMessage / ProcessMessages problem

[b][red]This message was edited by VampireFE at 2007-1-9 6:19:41[/red][/b][hr]
Hello,

I am making a program using TClientSocket. I connect to the server with it and when i am connected, i start sending data. The code simplified looks like this:

......
Client->Active=true;
while(!TermConnected)
{
Application->ProcessMessages(); // Application->HandleMessage();
}
......

TermConnected is changed to true when OnConnect occurs. (TClientSocket event) After that i start sending data to server. Normally it works ok, but sometimes ProcessMessages or HandleMessage functions break out from this function and never come back to it which screws everything up. Connection to the server is open but is never closed, because function doesn't end. And so, when i call this same function again, i cannot connect again, because only one session is allowed at the same time.

Anyone can help me understand this or have any solutions?

Edit: Ok, i figured out what happens.. these functions happen to launch one event, that is quite long and in there i call this function again. That is before processmessages/handlemessage is over.

So is there a way to work around this?

Comments

  • : Edit: Ok, i figured out what happens.. these functions happen to launch one event, that is quite long and in there i call this function again. That is before processmessages/handlemessage is over.
    :
    : So is there a way to work around this?
    Hi VampireFE,

    My first suggestion would be to call ProcessMessages() from an often called function. Or put a TTimer on the Form with the only task to call ProcessMessages(). Or work with two threads, one processing what the user is doing at any moment, the other doing the calculations.

    Hope to have helped you, Bilderbikkel
    bilderbikkel

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion