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?
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?
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?
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?