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 159015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:47:03+00:00 2026-05-11T10:47:03+00:00

I’m having some weird behavior in an application which is puzzling me. I create

  • 0

I’m having some weird behavior in an application which is puzzling me.

I create a thread, let’s call it worker, which is responsible for handling communication requests. Clients write on a pipe while the thread consumes the requests and send messages.

Now, the main loop of the thread has something like this:

lock(this) {   object_id = Transport.BeginSend(xxx, xxx, callback, yyy)   clientsObjects[object_id] = client_id; } 

now the callback needs to access the client_id (its a bit more complicated than what I wrote, but the thing is that the callback receives the object_id, just assume BeginSend is a call to UdpClient.BeginSend

void Callback(IAsyncResult ar) {   State st = (State)ar;   lock(this)   {     client_id = clientsObjects[st.object_id]   } } 

Locks are there because the callback may fire so fast that it actually happens before clientsObjects[object_id] = client_id; can execute…

Ok, now.. the problem is it’s not working, well it works now and then… why? If I trace the ManagedThreadIds of the threads which are executing the BeginSend and the one that is executing the callback I find that sometimes, they have the same ThreadId!!

Is that possible? How can that happen? Any suggestions about what am I doing wrong?

Comment: Actual code is not exactly like that, Transport is a wrapper around the UDPClient which allows changing the transport layer easily, locks aren’t really locks but spinlocks … but the concept itself is more or less what I’ve written down.

  • 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. 2026-05-11T10:47:03+00:00Added an answer on May 11, 2026 at 10:47 am

    Here is an older article that talks about the Stream.BeginRead() function actually operating synchronously, not asynchronously as you would expect. The article is from 2004, so I’m assuming it’s referring to .NET 1.0/1.1. The article does not specifically refer to UdpClient.BeginSend(), but I’ve often wondered if the BeginXXX functions in the Socket stuff have the same behavior at times, especially if there is data to be read immediately. It might be worth checking the web to see if this is a possibility.

    Is it possible to pass the client_id to the callback function via the state parameter of the BeginSend() function?

       object_id = Transport.BeginSend(xxx, xxx, Callback, client_id); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 200k
  • Answers 200k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The first error I found is that max will always… May 12, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer I did a test with the viewport set to the… May 12, 2026 at 7:59 pm
  • Editorial Team
    Editorial Team added an answer Aliases can't be used in group by clauses, nor can… May 12, 2026 at 7:59 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.