We help IT Professionals succeed at work.
Get Started

Advice using multiplethreads

Code_mechanic
on
196 Views
Last Modified: 2010-04-15
Q1
Im writing up a time server app that has the following thread hierarchy :(highest level =1)
(level1)  Thread  - does some time consuming work and spawns two server threads.
(level 2) server threads - these spawn separate threads for each connecting client and serves them asynchronously.
Now when i need to shutdown the servers i close all open connections, close listening sockets (System.net sockets) and kill the level 2 server threads. I have allowed a delay after killing the threads before spawning them again to restart servers. Is this a good approach to serving a huge number of clients asynchronously? Is there a standard way to doing it? what should i pay most attention to?

Q2
the form which spawns the server threads has a rich text box and a listview that needs to contain all server transactions. Therefore i need to be able to pass access to these controls into the server objects. I can pass them as arguments to the server constructor and use the lock(richtextbox) to lock the control before accessing it for thread safety and it seems to work fine. But whats the best way of solving the problem? In general i have used the lock(...) method when accessing shared datastructures and controls for thread safety. Is this a good way of doing it?

Q3
In my app i have multiple forms. when i spawn child forms from the parent there are cases where i need to call a childs method from the parent (eg passing a user input from an event in parent form). Is it cutomary to call the childform.method(param) directly from parent form?

Q4
When using a timer event, when it is raised if its carrying out some time consuming task, the caller gets blocked until timer event is all done. is it ok to run the timer on a separate thread for this reason? is there another approach?
Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 2 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE