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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:13:22+00:00 2026-05-24T17:13:22+00:00

I am using the following query var queryList1Only = (from file in list1 select

  • 0

I am using the following query

var queryList1Only = (from file in list1
                                  select file).Except(list2, myFileCompare);

while myFileCompare does a comparison of 2 files based on the name and length.

The query was returning the results if the list1 and list2 were small (say 100 files while I tested), then I increased the list1 to 30,000 files and list2 to 20,000 files and the query now says "Function Evaluation Timed Out".

I searched online and found debugging could cause it, so I removed all the breakpoints and ran the code, now the program just froze, without any output for queryList1Only I am trying to print out to check it.

EDIT:
This is the code for myFileCompare

class FileCompare : System.Collections.Generic.IEqualityComparer<System.IO.FileInfo>
    {

        public FileCompare() { }

        public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2)
        {
            return (f1.Name == f2.Name && f1.Directory.Name == f2.Directory.Name && 
                    f1.Length == f2.Length);
        }

        // Return a hash that reflects the comparison criteria. According to the 
        // rules for IEqualityComparer<T>, if Equals is true, then the hash codes must
        // also be equal. Because equality as defined here is a simple value equality, not
        // reference identity, it is possible that two or more objects will produce the same
        // hash code.
        public int GetHashCode(System.IO.FileInfo fi)
        {
            string s = String.Format("{0}{1}", fi.Name, fi.Length);
            return s.GetHashCode();
        }

    }
  • 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-24T17:13:24+00:00Added an answer on May 24, 2026 at 5:13 pm

    What are you need to do with the items returned by a query?
    Basically such heavy operations would be great to execute simultaneously in a separate thread to avoid the situations you’ve just faced.

    EDIT: An idea

    As a case you can try following algorithm:

    • Sort items in both arrays using QuickSort (List<T>.Sort() uses it by default), it will be pretty fast with good implementation of GetHashCode()
    • Then in well known for() loop traverse list and compare elements with the same index
    • When count of any array reaches maximum index of an other list – select all items from latter list as different (basically they are not exists in former list at all).

    I believe with sorted arrays you’ll give much better performance. I believe complexity of Except() is O(m*n).

    EDIT: An other idea, should be really fast

    • From one server store items in Set<T>
    • Then loop through second array and search within a Set<T>, it would be VERY fast! Basically O(mlogm) + O(n) because you need to traverse only single array and search within a set with good hash function (use GetHashCode() I’ve provided with an updated logic) is very quick. Try it out!
    // some kind of C# pseudocode ;)
    public IEnumerable<FileInfo> GetDifference()
    {           
        ISet<FileInfo> firstServerFilesMap = new HashSet<FileInfo>();
    
        // adding items to set
        firstServerFilesMap.Add();
    
        List<FileInfo> secondServerFiles = new List<FileInfo>();
    
        // adding items to list
        firstServerFilesMap.Add();
    
        foreach (var secondServerFile in secondServerFiles)
        {
            if (!firstServerFilesMap.Contains(secondServerFile))
            {
                yield return secondServerFile;
            }
        }
    }
    

    EDIT: More details regarding equality logic were provided in comments

    Try out this impelmentation

    public bool Equals(System.IO.FileInfo f1, System.IO.FileInfo f2)
    {
          if ( f1 == null || f2 == null)
          {
              return false;
          }
    
          return (f1.Name == f2.Name && f1.Directory.Name == f2.Directory.Name && 
                 f1.Length == f2.Length);
    }
    
    public int GetHashCode(System.IO.FileInfo fi)
    {
        unchecked
        {
            int hash = 17;    
            hash = hash * 23 + fi.Name.GetHashCode();
            hash = hash * 23 + fi.Directory.Name.GetHashCode();
            hash = hash * 23 + fi.Length.GetHashCode();
    
            return hash;
        }
    }
    

    Useful links:

    • GetHashCode Guidelines in C#
    • What is the best algorithm for an overridden System.Object.GetHashCode?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following query which works fine for me except one problem SELECT
Using the following query: SELECT pe.prodtree_element_name_l, MAX(rs.resource_value) AS resource_value FROM prodtree_element pe LEFT JOIN
i've been using the following query: select LEN(columnname) as columnmame from dbo.amu_datastaging This works,
I am getting random row from my table using the following query: SELECT value_id
I'm using LINQ-to-Entities. Using the following query: var x = from u in context.Users
I am using LINQPad to run the following query: var pds = (from p
I am using the following query in entity sql Select n.Name as NodeNameN from
I'm using the following code to execute a query in Lucene.Net var collector =
I'm trying to code the following HQL query using the Criteria API: var userList
I am trying the to query my Status Update repository using the following var

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.