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

  • Home
  • SEARCH
  • 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 9116357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:39:12+00:00 2026-06-17T04:39:12+00:00

If I have: lock(myLockObject) { mySharedBuffer.Modfiy(); something.BeginDoStuff(new Action(delegate() { mySharedBuffer.Modify(); })); } And the

  • 0

If I have:

lock(myLockObject)
{
    mySharedBuffer.Modfiy();
    something.BeginDoStuff(new Action(delegate()
        {
            mySharedBuffer.Modify();
        }));
}

And the callback supplied to BeginDoStuff() is called back on another thread – is the lock held/re-obtained when the callback is eventually run? (I presume the lock is lost and I need to lock again but cannot find the documentation saying so)

  • 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-17T04:39:14+00:00Added an answer on June 17, 2026 at 4:39 am

    is the lock held/re-obtained when the callback is eventually run?

    No – there’s no magic going on!

    BeginXXX returns immediately and control drops out of the lock block and the lock is released.

    If you want to obtain the lock again in the callback, you will need another lock block there.

    As with all locking, this means that you have to leave the mySharedBuffer object in a consitent state when the lock is released. Also, this object may be modified by another thread between the time you release the lock after BeginXXX and the time your callback obtains the lock again.


    If the implementation of BeginXXX can execute the callback synchronously, then the callstack will be just like normal sequential code and the lock will still be held. In this case, if you try to obtain the lock again in the callback, it will be obtained immediately because Monitor allows recursive lock acquisitions on the same thread.

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

Sidebar

Related Questions

I have the lock keyword in my code. It freezes because something else has
I have the following Lock statement: private readonly object ownerLock_ = new object(); lock
Do I have to lock access to instance members? Example: public class HttpModule :
I want my keyboard to have caps lock on, this is done by mEditText.setInputType(TYPE_TEXT_FLAG_CAP_CHARACTERS);
I have implemented a Pin-Lock viewController such that every time app becomes active, the
I have a test sample about coherence lock-unlock mechanism like this: public class Test
I have a multi-R/W lock class that keeps the read, write and pending read
I have a system set up to lock certain content in a database table
I have few questions about using lock to protect my shared data structure. I
I have a database and want to lock it ... I know I can

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.