Hi,

can some elaborate on
when to use a delegate's BeginInvoke or ThreadPool.QueueUserWorkItem?

Since they both semantically do the same, see following code.
NOTE, coding was done within the famous OutlookIDE... :)

// Delegate
class TestDelegate
{
  delegate void DoWorkDelegate();
  private DoWorkDelegate m_doWorkDelegate;

  public TestDelegate()
  {
    // create the delegate
    m_doWorkDelegate = new DoWorkDelegate(this.DoWork);
  }

  private void DoWork()
  {
    // do whatever is needed to do
  }
  public StartWork()
  {
    // start work within an other thread
    m_doWorkDelegate.BeginInvoke( null, null);
  }
}

// ThreadPool
class TestThreadPool
{
  private WaitCallback m_WaitCallback;

  public TestDelegate()
  {
    // create the waitcallback
    m_WaitCallback= new WaitCallback (this.DoWork);
  }

  private void DoWork(object state)
  {
    // do whatever is needed to do
  }
  public StartWork()
  {
    // start work within an other thread
    ThreadPool.QueueUserWorkItem(m_WaitCallback);
  }
}

// Ryan


-------------------------------------
The information included in this message is personal and/or confidential and
intended exclusively for the addressees as stated. This message and/or the
accompanying documents may contain confidential information and should be
handled accordingly. If you are not the intended reader of this message, we
urgently request that you notify Centric immediately and that you delete
this e-mail and any copies of it from your system and destroy any printouts
immediately.
It is forbidden to distribute, reproduce, use or disclose the information in
this e-mail to third parties without obtaining prior permission from
Centric. We expressly point out that there are risks associated with the use
of e-mail. Centric and the companies within the group shall not accept any
liability whatsoever for damage resulting from the use of e-mail. Legally
binding obligations can only arise for Centric by means of a written
instrument, signed by an authorized representative of Centric.
-------------------------------------

Reply via email to