I have an extension method which takes in two list and compares them for modifications then outputs a new list. Here is the code
public static List<Member> GetModifiedRecords(this List<Member> LocalMemberData, List<Member> RemoteMemberData)
{
var result = (from localdata in LocalMemberData
from remotedata in RemoteMemberData
where
((
localdata.Card != remotedata.Card ||
localdata.DateJoined != remotedata.DateJoined ||
localdata.DatePaidUpTo != remotedata.DatePaidUpTo ||
localdata.Forename != remotedata.Forename ||
localdata.Postcode != remotedata.Postcode ||
localdata.State != remotedata.State ||
localdata.Street != remotedata.Street ||
localdata.Surname != remotedata.Surname ||
localdata.Title != remotedata.Title ||
localdata.Town != remotedata.Town
)
&& (localdata.MemberNumber == remotedata.MemberNumber
))
select localdata).Distinct();
List<Member> modifiedMembers = new List<Member>(result);
return modifiedMembers;
}
What’s strange is when running it fails on the line
List<Member> modifiedMembers = new List<Member>(result);
With the error
“The CLR has been unable to transition from COM context 0x3b4668 to COM context 0x3b44f8 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.”
FYI both Lists that are being compared have over 100,000 records. Am I thinking about this wrong?
Consider a join, instead of filtering the cartesian product. For instance:
Gives timings of
i.e. joins are super fast (complexity O(n)), your pseudo-join isn’t (complexity O(n2)).
At 100000 items, my machine choked (I quit after 5 minutes) on the cartesian product filtering approach, but completed the join in 21ms.
So, rewriting your query as follows should really turbo things up: