[quoted text, click to view] On Fri, 30 Jun 2006 00:05:18 -0400, MuZZy wrote:
> Here's the thread class i wrote to support callback. Its imple and esay
> to extend if needed:
[...]
> public delegate void MyThreadStart();
> public class MyThread
> {
> protected MyThreadStart m_tsThreadStart;
[...]
> public void Start()
> {
> m_tsThreadStart.BeginInvoke(new AsyncCallback(CallBack), null);
> }
[...]
> }
> And when you create that thread object you just subscribe to its
> ThreadFinished event which will fire when the thread is done.
There's like a problem with your helper class. Typically, when somebody
wants to create their own thread instead of using a thread from the
ThreadPool (which is much more efficient), this is because they want to do
some long running operation. Doing a long running operation in a thread
taken from the ThreadPool is a no-no as you might end up starving the
ThreadPool. Yet, that's what you are doing in your class:
m_tsThreadStart.BeginInvoke(new AsyncCallback(CallBack), null);
Calling BeginInvoke() on a delegate doesn't create a new thread but causes
the fonction represented by the delegate to be executed in a thread from
the ThreadPool. This wouldn't be a problem if you made it clear that your
Start() method actually invoked the supplied delegate in a thread from the
ThreadPool and *not* from a new thread. But instead, you have given your
class the very misleading name "MyThread" which leads users to think that
this is just a wrapper for the Thread class; the name of its event
("ThreadFinished") adds to the confusion. I think that you should either
create a new thread in your Start() method instead of using the ThreadPool
or rename your class and make it very clear in the doc and explanation that