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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:54:12+00:00 2026-05-19T11:54:12+00:00

Have had a bit of a search, but couldn’t find the same situation I’m

  • 0

Have had a bit of a search, but couldn’t find the same situation I’m facing here.

Here’s the snippet I’m worried about:

    var threadsafeVacantStats = new Dictionary<Thread, StatsNode>();
    var threadSafeVacantLocker = new Object();
    var threadsafeZoneStats = new Dictionary<Thread, StatsNode>();
    var threadSafeZoneLocker = new Object();
    Parallel.ForEach(m_TeamAreasByZone[zone.ContainerID], team =>
    {
        var tempVacantStatNode = CreateASyncStatsNodes(threadSafeVacantLocker, threadsafeVacantStats);
        var tempZoneStatNode = CreateASyncStatsNodes(threadSafeZoneLocker, threadsafeZoneStats);
        //...other stuff
    }

Here’s the function it’s calling:

private static StatsNode CreateASyncStatsNodes(object threadSafeLocker, Dictionary<Thread, StatsNode> threadsafeTeamStats)
{
    StatsNode tempStatsNode;
    var currentThread = Thread.CurrentThread;
    lock (threadSafeLocker)
    {
        if (!threadsafeTeamStats.ContainsKey(currentThread))
            threadsafeTeamStats[currentThread] = new StatsNode(0, 0);

        tempStatsNode = threadsafeTeamStats[currentThread];
    }
    return tempStatsNode;
}

To me, this looks fine, however resharper is giving a warning for the second call to CreateASyncStatsNodes (the first call is fine).
Following its advice, it turns the block into:

var threadsafeVacantStats = new Dictionary<Thread, StatsNode>();
var threadSafeVacantLocker = new Object();
var threadsafeZoneStats = new Dictionary<Thread, StatsNode>();
var threadSafeZoneLocker = new Object();
object locker = threadSafeZoneLocker;
Dictionary<Thread, StatsNode> stats = threadsafeZoneStats;
Parallel.ForEach(m_TeamAreasByZone[zone.ContainerID], team =>
    {
        var tempVacantStatNode = CreateASyncStatsNodes(threadSafeVacantLocker, threadsafeVacantStats);
        var tempZoneStatNode = CreateASyncStatsNodes(locker, stats);
        //...
    }

This doesn’t really make sense to me, and doesn’t seem to actually fix anything (if it was even broken in the first place). Is resharper mistakenly marking giving a warning, or am I missing something?

  • 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-05-19T11:54:12+00:00Added an answer on May 19, 2026 at 11:54 am

    Resharper doesn’t know that Parallel.ForEach execute passed lambda immediately. It suppose that this lambda could be executed later, when closure will be modified and this could produce some problems. You can ignore this warning.

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

Sidebar

Related Questions

I've had a bit of a search around, but couldn't find anything similar to
I've had a bit of a search, but didn't find anything quite like what
I've done quite a bit of googling on this error but have had no
I have run into a bit of a problem here: I had a problem-specific
I tried to search a bit before asking but I really had no idea
For years, on 32-bit systems I have never had a problem. Why can't I
I have the following code setup: http://jsfiddle.net/bABHU/2/ Had to change it a little bit
I have had a look all over, but it doesn't seem as though my
Ive been able to compile Python 3.2 using VS2010, but have had no luck
I had a look at this thread before asking a question here. But that

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.