Click to See Complete Forum and Search --> : Not easy - Events, Threads and Forms


IAmChris
May 28th, 2004, 04:03 AM
Hi all,

I'm writing an Instant Messaging application that uses multiple objects called conversation, each referencing multiple connection objects. Each connection object has a network stream to a remote host in the conversation. Each connection has a thread to listen on the TCP stream and a thread to process any incoming messages received. Depending on the message received, different events are raised which are handled by the conversation object. For example, when a message is received stating that a party is leaving a conversation, the appropriate event is raised and the conversation object handles this by deleting the connection object, or at least the reference to it.

The conversation also references a form called frmConversation. Basically, even if the user closes this form the conversation is still active through the connection object. The coversation object is kind of like the frmConversation's parent. If the form is closed and a message is received, the form is reloaded and the message displayed.

The problem is that when a message is received, the events all fire fine. The form is loaded and the message is displayed (but not refreshed so i only see a blank form), but because the thread execution goes back to the connection object, the form dissappears. I think that the execution needs to end on the form but I can't make it do this as execution starts at the object. I've tried using a seperate thread to show the form and aborting the thread once the form is shown, all to no avail.

Can anyone help please. Am I right in assuming that execution needs to end in a form object? Any info would be appreciated.