C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 06-08-2003, 09:17 AM   #1
Just one more wrong move.
 
-KEN-'s Avatar
 
Join Date: Aug 2001
Posts: 3,232
Multithreading

I'm trying to do a simple server with the TcpListener class, and I'm using multithreading to handle the accept()'ing. Of course, that's sort of a hangover from C++ Winsock habits (I never could get a handle on asychronous sockets).

Anyway, my code looks like this:

Code:
void startClick(object sender, System.EventArgs e)
{
	server.Start();
			
	Thread thread = new Thread(new ThreadStart(Listen));

}

public void Listen()
{
	Socket accept;
	while(true)
	{	accept = server.AcceptSocket();
				
	         listBox.Items.Add(accept.RemoteEndPoint);
	 }
}
where startClick() is generated when the user clicks a button on the form to begin the server.

For some reason the thread is never generated, and the Listen() function is never called.


Also, is working with asynchronous sockets any easier in C# if so, maybe I should just do that...
__________________
Gays can't love like real people

entropysink.com -- because arses weren't designed for running websites.
-KEN- is offline   Reply With Quote
Old 06-08-2003, 07:26 PM   #2
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
Your program is fine, I'm having the exact same lines in some of mine... you are just missing one line:

Code:
void startClick(object sender, System.EventArgs e)
{
	server.Start();
			
	Thread thread = new Thread(new ThreadStart(Listen));

                thread.Start(); // !!! ;-)
}

public void Listen()
{
	Socket accept;
	while(true)
	{
	accept = server.AcceptSocket();
				
	         listBox.Items.Add(accept.RemoteEndPoint);
	 }
}
__________________
hth
-nv

She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

When in doubt, read the FAQ.
Then ask a smart question.
nvoigt is offline   Reply With Quote
Old 06-08-2003, 08:03 PM   #3
Just one more wrong move.
 
-KEN-'s Avatar
 
Join Date: Aug 2001
Posts: 3,232
Talk about a "duh" moment. Nvoigt...don't take this the wrong way...but I think I love you .
__________________
Gays can't love like real people

entropysink.com -- because arses weren't designed for running websites.
-KEN- is offline   Reply With Quote
Old 06-09-2003, 06:28 PM   #4
¡Amo fútbol!
 
Join Date: Dec 2001
Posts: 2,123
::Joke so easy that it's omitted::
golfinguy4 is offline   Reply With Quote
Old 06-13-2003, 10:11 PM   #5
Registered User
 
CompiledMonkey's Avatar
 
Join Date: Feb 2002
Location: Richmond, VA
Posts: 438
Hey man, everybody has those moments. Only god knows how many times I've done stupid $$$$ like that.
CompiledMonkey is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multithreading (flag stopping a thread, ring buffer) volatile ShwangShwing C Programming 3 05-19-2009 07:27 AM
multithreading in C++ manzoor C++ Programming 19 11-28-2008 12:20 PM
Question on Multithreading ronan_40060 C Programming 1 08-23-2006 07:58 AM
Client/Server and Multithreading osal Windows Programming 2 07-17-2004 03:53 AM
Multithreading JaWiB Game Programming 7 08-24-2003 09:28 PM


All times are GMT -6. The time now is 12:29 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22