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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:57:07+00:00 2026-06-07T05:57:07+00:00

I use Task Parallel Library and I need to synchronize access to a method

  • 0

I use Task Parallel Library and I need to synchronize access to a method but since Tasks don’t necessarily create threads for asynchronous operations, I can’t rely on using locks.

void Foo()
{
    lock(SyncRoot)
    {
        // Do stuff...
    }
}

What can I use instead of lock if I want to prevent simultaneous calls from multiple tasks to Foo? I need my tasks to call Foo, one by one.


  • ContinueWith is not an option.
  • I use .NET 4.
  • 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-07T05:57:09+00:00Added an answer on June 7, 2026 at 5:57 am

    From MSDN:

    Behind the scenes, tasks are queued to the ThreadPool, which has been enhanced with algorithms (like hill-climbing) that determine and adjust to the number of threads that maximizes throughput.

    So you can lock or any other threading synchronisation mechanism like ManualResetEvent or Memory barriers.

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

Sidebar

Related Questions

I'm trying to use the Task-Parallel-Library to offload expensive ADO.NET database access from the
I use Task Parallel Library to start some tasks, like so: public static void
I don't know the difference beetween await a task and use task.Wait() but for
I am trying to use the parallel task library to kick off a number
I need to execute 3 parallel tasks and after completion of each task they
Is there any way to use Task Parallel Library in multi computer scenarios ?
In my use of the Task Parallel Library in .net 4.0 I am wondering
In a C# 4 application I use a task parallel library for processing web
I'm using the TPL ( Task Parallel Library ) in .NET 4.0. I want
I'm researching the usage of the Task Parallel Library for a work project I'm

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.