If you want more details you will have to reference the VS.Net example
ConsoleChat for Networking How-to:
--
http://go.microsoft.com/fwlink/?link...rt/howto/sampl
es/net/TCPUDP/Chat.src
In trying to put it into a Windows form (c#.net, VS 2002) this is my
main:
[STAThread]
static void Main() {
Thread t =
new Thread(new ThreadStart(chatter.Listener));
try {
chatter.Initialize();
t.Start();
}
catch (Exception cex) {
chatter.Terminate();
MessageBox.Show(cex.Message);
if (t.IsAlive) {
t.Abort();
t.Join();
}
}
Application.Run(new Form1());
chatter.Terminate();
MessageBox.Show("Alive: "+t.IsAlive);
t.Abort();
MessageBox.Show("Alive: "+t.IsAlive);
t.Join();
MessageBox.Show("Alive: "+t.IsAlive);
}
--------------------
chatter is the class for the chat util where all this activity is
static--no instantiation of a chatter. (I know, it s/b capitalized.)
The only modifications to the code is the removal of Console.ReadLine
stuff since I now have a textbox. Also, chatter.Terminate() sets the
flag field which breaks the while loop within chatter.Listener().
It actually all works. However, the Thread refuses to unload. The last
3 MessageBoxes come back True, True, ...(never pops the last one). I
have to go to the TaskManager and kill the process.
I can get it to unload. If I comment out the:
chatter.Chatter += new MessageEventHandler(this.addChat);
which, of course, makes it stop handling the messages AND, (let me
repeat that) AND actually type a [return] into the textbox which,
coindidentally fires a KeydownEventHandler to trap the [return]. So
even disconnected from the chatter the thread sticks UNLESS I trigger
the other event handler which is entirely within the Windows Form.
Anybody have a clue for me?
thx
md
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!