I have a WPF app that tries to load large data from a csv file (I need for the data to be in memory as client requested). I already have a library that does this process, with the help of CsvHelper
When I run a console application it take less than a second to load, but when I use the same library with WPF, it's very slow takes about 18 seconds.
Is this normal? and if yes is there some sort of fix or should I just give up and accept that it's the way WPF is?
Note: The Core library that does the load is in .NET core
, I don't know if it's the problem.
EDIT:
Here is my code for importing the data.
public void ImportBookingData(Action<BookingRecord> processData, string path)
{
using (TextReader reader = new StreamReader(path))
{
CsvReader csv = new CsvReader(reader);
csv.Configuration.TypeConverterCache.AddConverter<DateTime>(new ShortDateTimeCsvConverter());
csv.Configuration.TypeConverterCache.AddConverter<TimeSpan>(new ShortTimeSpanConverter());
csv.Configuration.Delimiter = ";";
while (csv.Read())
{
processData.Invoke(csv.GetRecord<BookingRecord>());
}
}
}
To process the incoming records I use this code
importService.ImportBookingData(record =>
{
//Add record to indexed records
ConstructIndexedRecords(record);
//The start and end date will take the first record date in the initial stage
if (firstRecord)
{
StartDate = record.FlightDate;
EndDate = record.FlightDate;
}
//Search for time period of the input data records
CheckForLimitDates(record);
firstRecord = false;
}, path);
So I tied to place a stopwatch in various places to pinpoint where the problem is, I tested the speed of csv.Read()
and also the speed of reading all the records, and the results were the same. In the processing of the records, I put a stop watch to test the speed of processing one record, and the results were also the same. Finely when I test the entire time of the processing I get less then a second for the Console app, and 10 seconds for WPF. So what do you think? Does it has to do anything with using delegates?
Comments
Post a Comment