Storing a Form in a Hashtable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm working on a chat client and this is what I'm trying to do when a
message is received:

private void ReceivedMessage_Event(object sender,
ClientEventArgs e)
{
// the ChatWindow class is derived from a simple form
ChatWindow pm;

try
{
if (e.CommandType == CommandType.PrivateMessage)
{
// check to see if there is already a chat window
open
if (this.m_ChatTable.ContainsKey(e.SenderName))
{
// add the new message to the chat window
pm =
(ChatWindow)this.m_ChatTable[e.SenderName];
pm.AddMessage(e.MessageText);
}
else
{
// there is no window open so we have to create
one and show the form and the message
pm = new ChatWindow(e.SenderName,
this.m_userName);
pm.PrivateMessageSent += new
ChatWindow.PrivateMessageEventHandler(ChatWindow_PrivateMessageSent);
pm.FormClosing += new
FormClosingEventHandler(ChatWindow_FormClosing);
this.m_ChatTable.Add(e.SenderName, pm);
pm.AddMessage(e.MessageText);
pm.ShowDialog();
}
}
}
catch (InvalidOperationException ioe)
{
MessageBox.Show(ioe.StackTrace);
}

I'm getting a "System.InvalidOperationException occured in
MyProgram.exe" message. But the exception is only thrown when I close
the ChatWindow that is created in the "else" block. I've placed
try/catch blocks around every statement in my application but it still
goes unhandled. I'm willing to provide any code that may help you
understand what I'm trying to do. Right now this is the code that I
beleive is the most relevant. Please let me know if I need to provide
more information.

.



Relevant Pages

  • Re: activating windows from a separate thread - chat_window_activation_code.cs (0/1)
    ... I have to remote objects -- chat monitors - that handle the main connection stuff. ... So, in the chat handler thread, I call my own chat monitor, passing it in the remote monitor object ... through a callback method, to establish a chat window, giving the application a link to a local chat ...
    (microsoft.public.dotnet.framework.windowsforms)
  • flash a window on toolbar
    ... I have written a chat program using asp.net. ... It basically has a hidden frame ... take focus away from the chat window in which user is typing in messages. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Main Ostomy Chat
    ... Main Ostomy Chat is Saturday 8pm UK Time which is 3pm EST ish. ... Please join us for our first weekly chat on our own server. ... and join us in the ostomyland chat room from there. ... What Happened To The Main Site's Java Chat Client? ...
    (alt.support.mult-sclerosis)
  • Re: SQL Server SP4 Chat
    ... >>>Join members of the Product Group in a Chat about SP4. ... >>>>Join members of the SQL Server development team as we discuss what's>>coming>>up in SQL Server 2000 Service Pack 4. ... I somehow managed to get myself disconnected a> few times, once I saw only the guest chat window, not> the window with the expert's answers anf my two final attempts failed> because the same set of answers just kept repeating itself over and over> in the expert's answers windows, while at the same time nothing happened ... > If there's a transcript, I'd definitely want to read it. ...
    (microsoft.public.sqlserver.programming)
  • Re: simple RMI chat problem
    ... The chat server is registering itself correctly. ... themselves with the chat server, this means, the chat client objects ... Remote and register a unique service name to the rmi registery ...
    (comp.lang.java.programmer)