473,513 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Threadpool doubt

Hi,
I have some doubts about threadpool.

I have a function which does some calculation for long time and writes
the results to a file. Since I have to do multiple call to the same
functions, I used threadpool.

here is the snap shot of the function in brief...

private void DoMath(object Items)
{
//calculate another object and gets some value
.....
//writes the value to the file whose defination is defined as
global
........
//calculation here
........
Writes the value to the file
//calculate another object and gets some value
.....
//writes the value to the file whose defination is defined as
global
........
File.Flush()
}

I have to open 5 to 15 simultaneous calls to DoMath object.

I still couldn't make it work but I have couple of questions here.

1. File.Flush -- Will this writes all the value for the current
component or will it write all the values from other component ?.
2. if the above solution doesn't work...how do i organize the data in
this scenario ?.
3. How do I check all the threads excecuted successfully ?.
I used in main

int mWorkerThreads;
int mPortThreads;
int aWorkerThreads;
int aPortThreads;
ThreadPool.GetMaxThreads(out mWorkerThreads, out mPortThreads);
ThreadPool.GetAvailableThreads(out aWorkerThreads, out
aPortThreads);

if (mWorkerThreads == aWorkerThreads && mPortThreads ==
aPortThreads)
// Thread worked successfully...

I dont think it works fine though...

It will be helpful if you give some pointer to any website which
explains this..

Thanks.....
Nov 16 '05 #1
2 1539
rajesh,

See inline:
I have a function which does some calculation for long time and writes
the results to a file. Since I have to do multiple call to the same
functions, I used threadpool.
If the operations take a long time, then the thread pool might not be
the best solution for you. The thread pool is meant for short running
operations.
1. File.Flush -- Will this writes all the value for the current
component or will it write all the values from other component ?.
I assume that File is a FileStream instance. If so, then a call to
Flush will only flush the contents of the current stream.
2. if the above solution doesn't work...how do i organize the data in
this scenario ?.
If you need to flush all the streams, then you need to explicitly call
Flush on each stream. Also, make sure you are calling Close (or
IDisposable.Dispose) on the Stream.
3. How do I check all the threads excecuted successfully ?.
You should set a flag somewhere at the end of the code that executes in
the thread, and check the collection of flags. Counting the number of
threads in the threadpool is not going to do anything, because there are
many areas of the .NET framework that use them.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
I used in main

int mWorkerThreads;
int mPortThreads;
int aWorkerThreads;
int aPortThreads;
ThreadPool.GetMaxThreads(out mWorkerThreads, out mPortThreads);
ThreadPool.GetAvailableThreads(out aWorkerThreads, out
aPortThreads);

if (mWorkerThreads == aWorkerThreads && mPortThreads ==
aPortThreads)
// Thread worked successfully...

I dont think it works fine though...

It will be helpful if you give some pointer to any website which
explains this..

Thanks.....

Nov 16 '05 #2
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
I have a function which does some calculation for long time and writes
the results to a file. Since I have to do multiple call to the same
functions, I used threadpool.


If the operations take a long time, then the thread pool might not be
the best solution for you. The thread pool is meant for short running
operations.


Agreed. That doesn't mean you can't use *a* thread pool though - it's
just that the system thread pool probably isn't a good choice.

I have a thread pool class you can use in the library available at
http://www.pobox.com/~skeet/csharp/miscutil

Feel free to adapt it as you see fit, of course.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12301
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
5
387
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
5
2751
by: Duane Pressley | last post by:
I'm looking for someone to help me make sense of the results I'm observing when using the ThreadPool class in a COM-Interop scenario. Here's the set up: 1.. A classic ASP page instantiates and calls...
16
2614
by: NOtcarvinSPAM | last post by:
It occurs to me that if I have a work object that gets executed via QueueUserWorkItem AND the work proc accesses only that object's instance data I STILL may have to lock because the object...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.