473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ThreadPool - Terminating Function Exsists?

I have a thread pool. Is there a function I can override that all the
ThreadPool work queues call before they terminate? IE so I can just
do something like

override void _threadpoolterminate(...) {
//My 1 line of code "Running[this] = false;"
base(...);
}

Kinda thing...

I have about 50 functions I call with the ThreadPool, and each time
they return I have to do "Running[ThreadPoolItem] = false; return;".
And most the functions return at multiple spots... its gets a little
annoying/messy expecially if I forget to set running to false before a
return.
Thanks.
NB.

Nov 7 '06 #1
1 1763

"NvrBst" <qu****@hotmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
>I have a thread pool. Is there a function I can override that all the
ThreadPool work queues call before they terminate? IE so I can just
do something like

override void _threadpoolterminate(...) {
//My 1 line of code "Running[this] = false;"
base(...);
}

Kinda thing...

I have about 50 functions I call with the ThreadPool, and each time
they return I have to do "Running[ThreadPoolItem] = false; return;".
And most the functions return at multiple spots... its gets a little
annoying/messy expecially if I forget to set running to false before a
return.
Something like this:

class ThreadPoolHelper
{
public static Queue<ObjectType>(ObjectType that, string methodName, object
state)
{
ThreadPool.QueueUserWorkItem(new PoolShim<ObjectType>(obj,
typeof(ObjectType).GetMethod(methodName)).DoIt, state);
}

private class PoolShim<ObjectType>
{
delegate void WorkDelegate(ObjectType that, object state);
readonly ObjectType that;
readonly WorkDelegate action;

public PoolShim(ObjectType that, MethodInfo m)
{
this.that = that;
this.action = (WorkDelegate)Delegate.Create(typeof(WorkDelegate) ,
m);
}

public void DoIt(object state)
{
try {
action(that, state); // binds delegate at call time, like C++
(that->*action)(state)
}
finally {
Running[that] = false;
}
}
}
}

now, instead of
ThreadPool.QueueUserWorkItem(obj.method, state);

use
ThreadPoolHelper.Queue(obj, "method", state);
>

Thanks.
NB.

Nov 7 '06 #2

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

Similar topics

5
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...
2
by: rajesh | last post by:
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...
13
by: orekin | last post by:
Hi There I have been programming C# for a couple of months and am trying to master Threading. I understand that ThreadPool uses background threads (see code example in MSDN page titled...
4
by: objectref | last post by:
hi to all folks here, let's say that i am using a threadpool and somehow, some threads in it just stuck. (endless loop or something like that). So, if it receive a request to run for 25 times...
5
by: Henri | last post by:
Might sound a stupid question but need to be sure: When you call ThreadPool.QueueUserWorkItem and ThreadPool.RegisterWaitForSingleObject passing a New object as state e.g.:...
0
by: Ryan Linneman via .NET 247 | last post by:
I have a simple program to read data from a touchscreen overEthernet using a custom DLL provided by the touchscreenmanufacturer, and I want to read this data using the threadpool.When I use the...
1
by: colinjack | last post by:
Hi All, I've been using the original (non-event based) asynchronous design pattern using delegates. It works fine but performance wise I know using the ThreadPool is supposed to be far better,...
1
by: gnassar | last post by:
This question is prob. extremely trivial but I can't seem to find out what is going on. I've been doing some basic work with Multithreading and Worker Threads and have determined I'd like to set up...
1
by: Shree | last post by:
On Aug 22, 1:01 pm, "Brian Stoop" <b.st...@consultant-spam.free.com> wrote: A simple way could be to keep a static counter which can be updated in the call back function "TestThread1". Make the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.