ThreadPool - Terminating Function Exsists?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • NvrBst

    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 _threadpoolterm inate(...) {
    //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.

  • Ben Voigt

    #2
    Re: ThreadPool - Terminating Function Exsists?


    "NvrBst" <quickx@hotmail .comwrote in message
    news:1162940548 .648067.30450@e 3g2000cwe.googl egroups.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 _threadpoolterm inate(...) {
    //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 ThreadPoolHelpe r
    {
    public static Queue<ObjectTyp e>(ObjectType that, string methodName, object
    state)
    {
    ThreadPool.Queu eUserWorkItem(n ew PoolShim<Object Type>(obj,
    typeof(ObjectTy pe).GetMethod(m ethodName)).DoI t, state);
    }

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

    public PoolShim(Object Type that, MethodInfo m)
    {
    this.that = that;
    this.action = (WorkDelegate)D elegate.Create( typeof(WorkDele gate),
    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.Queu eUserWorkItem(o bj.method, state);

    use
    ThreadPoolHelpe r.Queue(obj, "method", state);
    >
    >
    Thanks.
    NB.
    >

    Comment

    Working...