Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8993859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:17:23+00:00 2026-06-15T23:17:23+00:00

I’am working on an UDP listener windows application, once an UDP message reach the

  • 0

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.

This routine is called asynchrnously.

Why asynch ?

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).

My questions :

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

I hope i am explianing well what i wanna achieve

Apologize for my bad english

Regards

xPridex

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

/// <summary>
/// Launch SendNotificationToEBSECW treatment.
/// </summary>
/// <param name="sender">object : UDPmsg_t_Mapping</param>
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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:17:24+00:00Added an answer on June 15, 2026 at 11:17 pm

    There is nothing obviously wrong with that code, but I do have a few comments:

    • new Thread does not use the thread pool, it always creates a new dedicated thread.
    • Neither creating a new dedicated thread nor using the thread pool will ensure threads are completed in order due to thread scheduling, the work done, and other things outside your control.

    If you must handle the messages in the order they are received, you should not handle each message in a separate thread. Instead, add each message to a queue and process each item in the queue sequentially in a background thread.

    Threads do not have any built-in way of alerting their creator when they are done, or returning results. If you want to do that, use System.MulticastDelegate.BeginInvoke; that uses the thread pool. If you want intermediate results while the thread runs, use BackgroundWorker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I'm trying to select an H1 element which is the second-child in its group
I have an array which has BIG numbers and small numbers in it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.