GUI App (Forms) with async tcp i/o

  • Thread starter Thread starter Yechezkal Gutfreund
  • Start date Start date
Y

Yechezkal Gutfreund

Is there any problems with running an aplication that might have several
outstanding
async tcp i/o applications (thus several threads running from the tread
pool) and
the same app having a GUI (Windows Forms) front end. I understand that
the run Applicaiton.Run(gui class) will spawn a thread (or maybe many) to
run the GUI i/o.

I have no idea if these are pool threads, or what if any negative
interaction
they may do to the worker tcp threads.

The working tcp threads will not be doing major computations. And anyway,
the priority is not to the GUI, but to the worker threads (they should run
at a higher priority if possible). (and if so, how does one do this with the
async thread pool mechanism).


--
==================================
Yechezkal Gutfreund
Chief Scientist
Kesser Technical Group, Inc.
==================================
 
The best way to do this depends on exactly what you are doing, however I
would not queue a work item to the thread pool which makes a blocking call,
because the thread pool has a maximum of 25 threads and you could soon
exhaust the pool. So if for example you want to have more than 25 sockets
open, only 25 could be handled at a time if you call them synchronously, and
any timer events would not get handled while all the worker threads were in
use. I think you have two basic choices.

The first is to start your own threads and then do synchronous socket calls
from these threads. This does not make explicit use of the thread pool. The
problem is that if you have many sockets and many threads you end up with a
lot of context switching and poorer performance.

The second way is to use the sockets entirely asynchronously. The callbacks
automatically get executed in the thread pool.This way you can run more
sockets more efficiently, but of course writing the code is a little bit
harder.

In all cases beware of updating the controls in the GUI from other threads
or the callbacks. You will get exceptions. You should use the InvokeRequired
property and the Invoke method on the controls if you want to do this.

I hope this helps.

--
Robert Jarratt
Microsoft
(e-mail address removed)

This posting is provided "AS IS" with no warranties, and confers no rights.
 
The first part of your answer is standard good O.S. practice.

I apologize for not making this clear, but we are firmly committed to
your second path. The information about Invoke is very useful. That
was exactly the information we wanted to know, about how threads my
race with each other in doing GUI updates.



--
==================================
Yechezkal Gutfreund
Chief Scientist
Kesser Technical Group, Inc.
==================================
 
Back
Top