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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:48:51+00:00 2026-05-10T22:48:51+00:00

I have these container objects (let’s call them Container) in a list. Each of

  • 0

I have these container objects (let’s call them Container) in a list. Each of these Container objects in turn has a DataItem (or a derivate) in a list. In a typical scenario a user will have 15-20 Container objects with 1000-5000 DataItems each. Then there are some DataMatcher objects that can be used for different types of searches. These work mostly fine (since I have several hundred unit tests on them), but in order to make my WPF application feel snappy and responsive, I decided that I should use the ThreadPool for this task. Thus I have a DataItemCommandRunner which runs on a Container object, and basically performs each delegate in a list it takes as a parameter on each DataItem in turn; I use the ThreadPool to queue up one thread for each Container, so that the search in theory should be as efficient as possible on multi-core computers etc.

This is basically done in a DataItemUpdater class that looks something like this:

public class DataItemUpdater {     private Container ch;     private IEnumerable<DataItemCommand> cmds;      public DataItemUpdater(Container container, IEnumerable<DataItemCommand> commandList)     {         ch = container;         cmds = commandList;     }      public void RunCommandsOnContainer(object useless)     {         Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;         foreach (DataItem di in ch.ItemList)         {             foreach (var cmd in cmds)             {                 cmd(sh);             }         }         //Console.WriteLine('Done running for {0}', ch.DisplayName);     } } 

(The useless object parameter for RunCommandsOnContainer is because I am experimenting with this with and without using threads, and one of them requires some parameter. Also, setting the priority to AboveNormal is just an experiment as well.)

This works fine for all but one scenario – when I use the AllWordsMatcher object type that will look for DataItem objects containing all words being searched for (as opposed to any words, exact phrase or regular expression for instance).

This is a pretty simple somestring.Contains(eachWord) based object, backed by unit tests. But herein lies some hairy strangeness.

When the RunCommandsOnContainer runs using ThreadPool threads, it will return insane results. Say I have a string like this:

var someString = '123123123 - just some numbers'; 

And I run this:

var res = someString.Contains('data'); 

When it runs, this will actually return true quite a lot – I have debugging information that shows it returning true for empty strings and other strings that simply do not contain the data. Also, it will some times return false even when the string actually contains the data being looked for.

The kicker in all this? Why do I suspect the ThreadPool and not my own code?

When I run the RunCommandsOnContainer() command for each Container in my main thread (i.e. locking the UI and everything), it works 100% correctly – every time! It never finds anything it shouldn’t, and it never skips anything it should have found.

However, as soon as I use the ThreadPool, it starts finding a lot of items it shouldn’t, while some times not finding items it should.

I realize this is a complex problem (it is painful trying to debug, that’s for sure!), but any insight into why and how to fix this would be greatly appreciated!

Thanks!

Rune

  • 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-10T22:48:52+00:00Added an answer on May 10, 2026 at 10:48 pm

    It’s a bit hard to see from the fragment you’re posting, but judging by the symptoms I would look at the AllWordsMatcher (look for static state). If AllWordsMatcher is stateful you should also check that you’re creating a new instance for each thread.

    More generally I’d look at all the instances involved in the matching/searching process, specifically at the working objects being used when multithreaded. From past experience, the problem usually lies there. (It’s easy to look too much at the object graph representing your business data Container/DataItem in this case)

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

Sidebar

Ask A Question

Stats

  • Questions 387k
  • Answers 387k
  • 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 Honestly, when it comes to using Joins I stick with… May 15, 2026 at 12:06 am
  • Editorial Team
    Editorial Team added an answer Try connecting by specifying a port, eg: servername,1433 or servername\instance,1433 May 15, 2026 at 12:06 am
  • Editorial Team
    Editorial Team added an answer my advice is use plugin JSON.js ( http://devpro.it/code/149.html ) you… May 15, 2026 at 12:05 am

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.