Asynchronous delegates vs Threads

Viewed 10819

Replacing Threads (not ThreadPool Thread) with Asynchronous Delegates (Callbacks).

My Scenario: Spawn a Thread/del.beginInvoke() per Client.

According to me,

Reasons

  1. need for Notification via Callback / Call delegate again in Callback
  2. Avoid Thread Overhead, (delegates use Threadpool thread)
  3. Passing Arguments (Avoid Casting to object) and need return value from the method.

Correct me if above reasons are wrong.

  1. Is any other Reasons?
  2. What scenario i exactly need to do some stuff with Asynchronous Delegates that threads can't?
    3.Performance ?

Example

    public delegate void SendCallbackType();

    SendCallbackType senderdel= new SendCallbackType(SendData);

    public void StartSend() // This method Could be Called more than 700 times (Thread per Client)
    {
        senderdel.BeginInvoke(SendCallback,null);
                   // (or)
        Thread t = new Thread(new ThreadStart(ThreadSend));
        t.IsBackground = true;
        t.Start();
    }

  //Async Delegate
    void SendData()
    {
         string data = QueData.DeQueue();
         RaiseOnData(data); // Raise to event.
    }
    void SendCallback(IAsyncResult ar)
    {
        senderdel.BeginInvoke(SendCallback, null);
    }

 //Thread
  void ThreadSend()
  {
      while (true)
      {
         string data = QueData.DeQueue();
         RaiseOnData(data); // Raise to event.
      }
   }

From the above which option would be the best. Performance ?

1 Answers
Related