Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have a Form inside which i have two tabPages.Inside the first TabPage i have multiple nested TabPages each of these TabPages are created at runtime dynamically by the user.In each of these TabPages, i have a DataGridView containing many rows(row count differs in each datagridview of the TabPage). Every row of the datagridview contains few files which are to be sent to the client machines,i.e. every datargridview can have more than one client connection. I am not able to understand how to identify which tabPage is currently selected, which tabPage has completed sending all files to the clients .
What i am thinking is to associate a Master Thread with every nested TabPage and multiple worker threads inside each Master thread to connect to the client machine.Also is was thinking to use Hash Table to store the tabPage and its corresponding Thread ID but i am not sure and also i dont know how to implement it.
Can anyone give me a few guidelines.
In urgent need of help!!!
Posted

1 solution

There is no such concept as "master thread". Essentially, all threads are equal in this respect: in any thread, you can create and start other threads. (And then the threads can have different priorities, apartment states, anything.)

The methods of doing these are: 1) creating a thread using thread constructor, 2) using a thread from a thread pool, 3) using BackgroundWorker:
http://msdn.microsoft.com/en-us/library/xx3ezzs2.aspx[^],
http://msdn.microsoft.com/en-us/library/5cykbwz4.aspx[^],
http://msdn.microsoft.com/en-us/library/system.threading.threadpool.aspx[^],
http://msdn.microsoft.com/en-us/library/kbf0f1ct.aspx[^],
http://msdn.microsoft.com/en-us/library/4yd16hza.aspx[^],
http://msdn.microsoft.com/en-us/library/vstudio/system.componentmodel.backgroundworker[^].

The idea to create many threads (essentially, considerably more that the total number of CPU cores on the system) would be quite questionable. It can only reduce overall throughput. This idea of having a thread per item (whatever the item is) can be justified only if the items should implement logically independent behavior overlapping in time. If this is simply few nearly identical tasks which can be done in parallel, it would be a bad excuse for actually doing it in parallel. Think about doing it in sequence, to reduce the performance overhead.

However, a completely different story is using TPL. It is based on threads, but different tasks don't have to be on different threads. The system can properly optimize the performance, well or not so well, but this is not as crazy as using N threads. So, this is the alternative to threads you can consider. Please see:
http://en.wikipedia.org/wiki/Parallel_Extensions#Task_Parallel_Library[^],
http://msdn.microsoft.com/en-us/library/dd460717%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 
Comments
sovit agarwal 5-Jun-14 2:38am    
The tasks that the thread will be performing is the same , ie, every thread connects to a client machine and does the job of transferring few files from server to client. So this has to be done parallel connecting all the clients listed at the same time rather than waiting for communication to finish and then starting the other

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900