Closing Com port while receiving data

I want to close the terminal (VaComm) when certain strings are encountered in the RxChar buffer. However I have found that calling VaComm1.Close; while inside the RxChar procedure causes the Comms process / thread to lock up completely.

Is this a bug? 
If not, is there a technique, method or event I should use to close the com port based on events that occur inside the RxChar procedure?

It is not recommended to close the COM port from inside this event.

You might set a flag from this event and from your application main thread then close the COM port.

Hi Bruno,


Thanks for the fast reply, however I have been trying to do that but so far it still won't work. 

I set a flag and have a timer close the com port based on the flag. But it still locks up.

David.

Hi Bruno,


Made some more changes and it seems to work now.

It does seem a bit of a kluge though, having a timer hanging around waiting to close the port down! 

David.