How can I generate a thread dynamically in an efficient and controlled manner? The threads are to be created dynamically based on each XML host id.
Example:
samplethread1 for hostid:-1
samplethread2 for hostid:-2
Because I cannot rely on the host id count I need to make my code dynamic: suggest how I can have a control on each thread.
Given a piece of sample XML code:
<?xml version="1.0" standalone="yes"?>
<HOSTS>
<Host id = '1'>
<Extension>txt</Extension>
<FolderPath>C:/temp</FolderPath>
</Host>
<Host id = '2'>
<Extension>rar</Extension>
<FolderPath>C:/Sample</FolderPath>
</Host>
</HOSTS>
I have to agree that the question is not particularly clear. But if you are looking to just create a new thread for every host, then how about this? This is using the .NET 4.0 Task Parallel Library. From .NET 4.0 onwards this is an easy way to harness the concurrent capabilities of your processor.
If you’re using .NET 3.5 or previous, then you can just create the threads yourself:
This for me is still the best guide to Threading.
EDIT
So this is the task based version of what I think you’re getting at in your comment?