Click here to Skip to main content
15,920,632 members
Home / Discussions / C#
   

C#

 
QuestionAssume 3 or 5 textbox which will be filled by user at runtime and these values should assigned to radio button text which will be created dynamically. [modified] Pin
B875-Nov-08 22:18
B875-Nov-08 22:18 
AnswerRe: Consider 3 or 5 textbox which will be filled by user at runtime and these values should assigned to radio button text will be created dynamically. PinPopular
J4amieC5-Nov-08 22:22
J4amieC5-Nov-08 22:22 
GeneralRe: Consider 3 or 5 textbox which will be filled by user at runtime and these values should assigned to radio button text will be created dynamically. Pin
B875-Nov-08 22:44
B875-Nov-08 22:44 
GeneralRe: Consider 3 or 5 textbox which will be filled by user at runtime and these values should assigned to radio button text will be created dynamically. Pin
Shyam Bharath5-Nov-08 22:52
Shyam Bharath5-Nov-08 22:52 
GeneralRe: Consider 3 or 5 textbox which will be filled by user at runtime and these values should assigned to radio button text will be created dynamically. Pin
J4amieC5-Nov-08 23:18
J4amieC5-Nov-08 23:18 
AnswerRe: [modified - To remove stupidly long subject line] Pin
DaveyM695-Nov-08 23:27
professionalDaveyM695-Nov-08 23:27 
QuestionAsync callback usage in TCP server application Pin
Metal765-Nov-08 21:58
Metal765-Nov-08 21:58 
AnswerRe: Async callback usage in TCP server application Pin
Nicholas Butler6-Nov-08 0:18
sitebuilderNicholas Butler6-Nov-08 0:18 
Hi again Andrea. That's looking good.

Metal76 wrote:
1) Suppose you have several clients connected. Do all the callbacks (OnClientConnect, OnClientRead...) "live" in the same thread? That is, while I'm inside OnClientRead to serve one of the clients, can my code be interrupted by an OnClientRead from another client?

I performed a simple investigation, and it seems that OnClientRead for different clients are called from the same thread. So, it seems that OnClientRead execution never gets interrupted. Am I right? Is this always true? If so, I think I can safely remove all the lock statements for clientList access.


The callbacks happen on a thread pool thread. This means that each callback owns it's thread while it is executing and will not be 'interrupted'. However, the thread pool has many threads! Each callback is handled separately, so it may or may not execute on the same thread pool thread each time.

If multiple clients are active at the same time, you may have many threads from the pool, each executing OnClientConnect or OnClientRead for a particular client. This means that you do have to protect your shared state ( clientList ) by using a lock, just as you have done.

Metal76 wrote:
2) Is it correct to always launch a new AsyncCallback every time? e.g. new AsyncCallback(OnClientRead) inside OnClientRead. Does this waste resources? Should I keep a different AsyncCallback for each client and reuse it?


Yes, you have to start a new BeginXXX call each time to continue accepting clients and receiving data. The AsyncCallback is just a delegate, so doesn't waste much. You can declare an instance in your class, instantiate it in a constructor, and reuse it each time. It doesn't really matter, though.

Just as a matter of style, I would put the calls to BeginAccept and BeginReceive in a private method each, just so you don't have two copies of each call.

Nick

----------------------------------
Be excellent to each other Smile | :)

GeneralRe: Async callback usage in TCP server application Pin
Metal766-Nov-08 0:56
Metal766-Nov-08 0:56 
GeneralRe: Async callback usage in TCP server application Pin
Nicholas Butler6-Nov-08 1:41
sitebuilderNicholas Butler6-Nov-08 1:41 
GeneralRe: Async callback usage in TCP server application Pin
Metal766-Nov-08 2:14
Metal766-Nov-08 2:14 
Questioncrystal report with dynamic columns? Pin
kieu duc khuong5-Nov-08 21:21
kieu duc khuong5-Nov-08 21:21 
AnswerRe: crystal report with dynamic columns? Pin
Programm3r6-Nov-08 1:22
Programm3r6-Nov-08 1:22 
AnswerRe: crystal report with dynamic columns? Pin
nelsonpaixao6-Nov-08 13:27
nelsonpaixao6-Nov-08 13:27 
GeneralRe: crystal report with dynamic columns? Pin
kieu duc khuong6-Nov-08 14:23
kieu duc khuong6-Nov-08 14:23 
GeneralRe: crystal report with dynamic columns? Pin
nelsonpaixao7-Nov-08 14:06
nelsonpaixao7-Nov-08 14:06 
QuestionContextSwitchDeadlock Pin
dec825-Nov-08 21:03
dec825-Nov-08 21:03 
AnswerRe: ContextSwitchDeadlock Pin
Nicholas Butler5-Nov-08 23:41
sitebuilderNicholas Butler5-Nov-08 23:41 
AnswerRe: ContextSwitchDeadlock Pin
DaveyM695-Nov-08 23:43
professionalDaveyM695-Nov-08 23:43 
QuestionFunction keys Pin
sram155-Nov-08 20:40
sram155-Nov-08 20:40 
AnswerRe: Function keys Pin
leppie5-Nov-08 22:38
leppie5-Nov-08 22:38 
AnswerCP IGNORE: Cross post three forums Pin
leckey6-Nov-08 10:06
leckey6-Nov-08 10:06 
QuestionProblem running a .bat file from a C# forms application Pin
Member 41835605-Nov-08 20:08
Member 41835605-Nov-08 20:08 
AnswerRe: Problem running a .bat file from a C# forms application Pin
Franck Paquier5-Nov-08 20:54
Franck Paquier5-Nov-08 20:54 
GeneralI agree it looks like a working dir problem - specify the error that you get Pin
Natza Mitzi5-Nov-08 22:39
Natza Mitzi5-Nov-08 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.