I seem to be having trouble with Threading.
First let me explain how the application is built.
I have a class that extends ApplicationContext, witch is my core class for the whole application, within this class I load new windows such as the login window.
then each window talks back and forth to the application context class.
I have a method that is used to open a new message window, here it is.
public void InitiateChat(RosterItem Roster)
{
MessageWindow MessageWindow;
if (WindowManager.ContainsKey(Roster.Jid.Bare) == false)
{
MessageWindow = new MessageWindow(Roster);
MessageWindow.FormClosing += new FormClosingEventHandler(MessageWindow_FormClosing);
//Store it.
WindowManager.Add(Roster.Jid.Bare, MessageWindow);
}
else
{
MessageWindow = WindowManager[Roster.Jid.Bare];
}
if (MessageWindow.InvokeRequired)
{
MessageWindow.BeginInvoke(new InitiateChatDelegate(InitiateChat), new Object[] { Roster });
return;
}
if (MessageWindow.WindowState == FormWindowState.Minimized)
{
MessageWindow.WindowState = FormWindowState.Normal;
}
MessageWindow.Show();
MessageWindow.Activate();
}
Now when I run the following code from an OnClick event in the main messenger window it works fine:
RosterItem RosterItem = GetSelectedContact();
if (RosterItem != null)
{
Messenger.Bootload.MessengerApplication.Instnace.InitiateChat(RosterItem);
}
The window works perfectly, but as this is a messenger application based on XMPP and agsXMPP i have an event witch is triggered by agsXMPP called OnMessage, witch sends me a notification that I have an incoming message.
here is that method.
public void ClientConnection_OnMessage(Object Sender, agsXMPP.protocol.client.Message Message)
{
//Load the contacts Window
RosterItem RosterItem = ContactManager[Message.From.Bare];
if (RosterItem != null)
{
InitiateChat(RosterItem);
}
}
The problem is that when I message comes out I run the InitiateChat method but it freezes :(
Its the MessageWindow.Show() thats cant run fine
Can anybody help me get this to work, I'v been trying to do it for a few days now.