Run routine asynchrnously even execution is hold in child thread?
<p>I'am working on an UDP listener windows application, once an UDP message reach the application i create a new dedicated thread which do a routine relatred to this udp message.</p>

<p>This routine is called asynchrnously.</p>

<p>Why asynch ?</p>

<p>mainly to keep the order in wich the UDP are coming , since asynchronous call are queued in threadpool (not the case if i let each thread run synch).</p>

<p>My questions :</p>

<ul>
<li>Is it a good idea to run a routine asynchronously even this routine run in a child thread ?</li>
<li>if yes, shall i implement IsBusy best pratice for this asynch call, even it's a fire and forget pattern ?</li>
</ul>

<p>I hope i am explianing well what i wanna achieve </p>

<p>Apologize for my bad english</p>

<p>Regards</p>

<p>xPridex</p>

<p>N.B : this not the accurate code i have delete lot of details with regard to lisibity.</p>

<pre><code>/// &lt;summary&gt;
/// Launch SendNotificationToEBSECW treatment.
/// &lt;/summary&gt;
/// &lt;param name="sender"&gt;object : UDPmsg_t_Mapping&lt;/param&gt;
private void StartPrepared(object sender)
{
            mainThread = new Thread(new ParameterizedThreadStart(EntryPointV3));
            mainThread.Start(sender);
}

private readonly object _sync = new object();
private bool _myTaskIsRunning = false;

public bool IsBusy
{
  get { return _myTaskIsRunning; }
}


public void DoWorkAsynch(Tuple.Create(x,y))
{
  MyTaskWorkerDelegate worker = new MyTaskWorkerDelegate(EntryPointV3);
  AsyncCallback completedCallback = new AsyncCallback(MyTaskCompletedCallback);

  lock (_sync)
  {
    if (_myTaskIsRunning)
      throw new InvalidOperationException("currently busy.");

    AsyncOperation async = AsyncOperationManager.CreateOperation(null);
    worker.BeginInvoke(Tuple.Create(x,y), completedCallback, async);
    _myTaskIsRunning = true;
  }
}

private void MyTaskCompletedCallback(IAsyncResult ar)
{
  // get the original worker delegate and the AsyncOperation instance
  MyTaskWorkerDelegate worker =
    (MyTaskWorkerDelegate)((AsyncResult)ar).AsyncDelegate;
  AsyncOperation async = (AsyncOperation)ar.AsyncState;

  // finish the asynchronous operation
  worker.EndInvoke(ar);

  // clear the running task flag
  lock (_sync)
  {
    _myTaskIsRunning = false;
  } 

  // raise the completed event
  AsyncCompletedEventArgs completedArgs = new AsyncCompletedEventArgs(null,
    false, null);
  async.PostOperationCompleted(
    delegate(object e) { OnMyTaskCompleted((AsyncCompletedEventArgs)e); },
    completedArgs);
}

public event AsyncCompletedEventHandler MyTaskCompleted;

protected virtual void OnMyTaskCompleted(AsyncCompletedEventArgs e)
{
  if (MyTaskCompleted != null)
    MyTaskCompleted(this, e);
}
</code></pre>
