Multi-threading problem!

  • Thread starter Thread starter Vadivel Kumar
  • Start date Start date
V

Vadivel Kumar

I have some hundred files (or webpages, just for example sake) which i have
to process
for some business logic. I have to read this files and do some thing as per
the given requirement.

I thought of using threads to do this. So, i tried to create some 10 threads
which concurrently
read the files and give it back to my business logic layer. A static
function will take a parameter which is a file name
and give it to the callback function (async mode) which will read and do all
the stuff....

Now, the issue is all my threads are ending before the operation is over. I
tried using Monitor.Wait, nothing happens properly.

I request you guys to give me some sample code or article which could be the
same kind

Thanks in Advance
Vadivel Kumar
 
Vadivel,

I can see creating one thread to do the work so that any GUI you have
doesn't hang up. Do you have reason to believe that if you did all of
the work on one thread then that thread would be spending a lot of time
in a waiting state? Try that approach first. If the CPU is well
utilized then it won't buy you much to use more threads.

Brian
 
Vadivel Kumar said:
I have some hundred files (or webpages, just for example sake) which i have
to process
for some business logic. I have to read this files and do some thing as per
the given requirement.

I thought of using threads to do this. So, i tried to create some 10 threads
which concurrently
read the files and give it back to my business logic layer. A static
function will take a parameter which is a file name
and give it to the callback function (async mode) which will read and do all
the stuff....

Now, the issue is all my threads are ending before the operation is over. I
tried using Monitor.Wait, nothing happens properly.

I request you guys to give me some sample code or article which could be the
same kind

Have a look at
http://www.pobox.com/~skeet/csharp/threads

If that doesn't help you, try to write a short but complete program
that demonstrates the problem.
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

However, I'd go along with what Brian said - having lots of threads
probably isn't a good idea.
 
Thanks Jon, for giving me a guidelines of how to post good.
But, I got solved the problem and it is working fine.

Thanks & Regards
Vadivel Kumar
 
Back
Top