problem activating closed form

Feb 12 2009 12:46 AM
 My program waits for incoming messages

private void OnMessage(object sender,...)
{
              if (msg.Body != null)
                {
                    lock (message) //message is Queue variable
                    {
                        message.Enqueue(m);
                    }
                    
                }
}

on my main thread i have a gridview with roster, when i click an item a form will pop out using this snippet
public void CreateForm()
{
 ChatForm y = new ChatForm();
 Application.Run(y);
}
y has a worker thread that listens to incoming message, compares the content of the message and dequeues it if the message is for this form..I also used FormsCollection() class to store all the instances of forms in the collection.This is already working.

This time i want to change the OnMessage method with this...(It's because i want to pop the Chat Form whenever new message came and no form is visible)

private void OnMessage(object sender,...)
{
              if (msg.Body != null)
                {
                    lock (message) //message is Queue variable
                    {
                        message.Enqueue(m);
                    }
                    
                }


                foreach (Form LoopForm in Forms) //check the forms in the collection
                {
                    if (LoopForm.Name.Trim() == "whatever name clicked")
                    {
                        if (LoopForm.Visible == false)//to check if the form is active and visible
                        {
                           
                           //Please suggest what to do here
                           if i were to use use CreateForm again
                           i noticed that the form is diplayed but can't display messages unless i                          click the close button..i don't know if it has something to do with multiple                      instance of Application.Run
                        }
                        else
                        {
                            //if form is visible
                            i can receive messages here since form is visible and active.
                        }


                    }
                    else
                    {
                       //my code here is ok..
                    }
              }
I'm having hard time displaying form closed or hidden or not yet created to display message queue..Please help..