473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Thread unloads fine in "DOS" not Windows

M D
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!
Nov 16 '05 #1
1 1459
M D
I got it.

The DOS version works because the flag governing the while loop in the
listener is flipped by a message received by the listener. When I
included a 'bye' message in the closing process, the while loop
completed allowing the thread to abort.

thx
md

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what...
24
by: Apotheosis | last post by:
The problem professor gave us is: Write a program which reads two integer values. If the first is less than the second, print the message "up". If the second is less than the first, print the...
11
by: Paminu | last post by:
Is there something like system("PAUSE") for linux?
3
by: atlantix | last post by:
How do you execute a .BAT file from a C# WinForm? An example would be greatly appreciated. Thanks, atlantix
4
by: Brent | last post by:
Take this string: "---------------------------------------- " (i.e., hyphens followed by a newline ) I thought I could match it simply with this Regex: "-*?\n"
1
by: Martin | last post by:
how to use Net View dos command with vb.Net? i want to bacame a string or array or some thing else! Im new so plz. help me with this Problem. thx for your help and Ideas thx
5
by: dananrg | last post by:
Is there a standard library module in Python 2.4 (Win32) that will return directory permissions / ACLs (e.g. users, groups, and what rights they have)? Otherwise, I'm faced with sending "cacls...
12
by: Djuro.Tost | last post by:
Thanks in advance... Robert...;)
3
by: priyabharathi | last post by:
instedof #include"dos.h" which header file is used in unix?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.