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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:05:25+00:00 2026-06-06T21:05:25+00:00

I recently started a WPF application. I connected that to a BaseX (XML-based) database

  • 0

I recently started a WPF application. I connected that to a BaseX (XML-based) database and retrieved about one million entries from it. I wanted to iterate over the entries, calculate something for each entry and then write that back to the database:

IEnumerable<Result> resultSet = baseXClient.Query("...", "database");
foreach (Result result in resultSet) 
{
    ...
}

The problem: The inside of the foreach is never reached. the Query() method returns pretty fast, but when the foreach is reached C# seems to do SOMETHING with the collection, the code is not continuing for a very very long time (at least 10 minutes, never let it run any longer).
What’s going on here?
I tried to limit the number of items retrieved. When retrieving 100.000 results, the same thing occurs but the code continues after about 10-20 seconds. When retrieving the full one million results, C# seems to be stuck forever…

Any ideas?
regards

Edit: Why this is happening
As some of you pointed out, the reason for this behavior seems to be that the query is actually only evaluated when MoveNext() on the Enumerator inside the Enumerable is called. My database seems unable to return one value at a time, but instead returns the entire one million dataset at once. I will try to switch to another database (Apache Lucene, if possible, as it has good fulltext search support) and edit this post to let you know if it changed anything.
PS: Yes, I am aware that one million results is a lot. This is not meant for live usage, it is just a step for preparing the data. While I didn’t expect the code to run in a few seconds, I was still surprised to see SUCH poor performance in the database.

Edit: The Solution So I migrated the XML database to Apache Lucine. Works like a charm! Of course Lucine is a text-based database that is not suitable for every use case, but for me it worked wonders. Can iterate over one million entries in a few seconds, one entry per loop is fetched – works extremly well!

  • 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-06T21:05:25+00:00Added an answer on June 6, 2026 at 9:05 pm

    One million of anything is a lot… so any operation that obtains that many items is expected to take significant amount of time. It looks like library you use does not defer retrieving items till it is absolutely necessary – so you see impact of getting all items hidden behind “foreach” statement.

    What happens:

    “foreach” is not a single operation, but rather several calls on IEnumerable and IEnumerator: IEnumerable.GetEnumerator, repeated calls to IEnumerator.MoveNext.

    First call GetEnumerator may be implemented with deferred execution (most common way how LINQ queries are written) or immediate execution (which seem to be the case of your collection.

    Calls to MoveNext could also trigger immediate execution of whole query even if you are asking just for single item or each call can get just single item. I.e. most LINQ queries get just one next item from iterator.

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

Sidebar

Related Questions

I recently started using WPF and the MVVM framework, one thing that I have
I've recently started creating a WPF application, and am just hoping that someone can
We are using the prism and WPF to build application. Recently we started using
When I started to learn about WPF and MVVM recently, I came across some
I recently started using C# and WPF for one of my projects. Is there
I've recently completed a fairly large (for one man) WPF project, and started coding
I've (very) recently started studying about Prism (for a WPF app) and I've been
I've recently started develping an application using WPF and I'cant really wrap my mind
I have recently started programming in WPF and bumped into the following problem. I
I've recently been learning the MVVM pattern in WPF and just started making my

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.