Page 1 of 1

ImportCSV MultiThread

Posted: Wed Sep 09, 2020 8:18 am
by zhuhy87
Method importcsv of txlsreadwriteii5
Does the read support multithreading

Re: ImportCSV MultiThread

Posted: Wed Sep 09, 2020 9:37 am
by larsa
Hello

Probably. Please do a test.

Re: ImportCSV MultiThread

Posted: Wed Sep 09, 2020 10:25 am
by zhuhy87
larsa wrote:Hello

Probably. Please do a test.
Hello
In fact, I want to ask if the XLSReadWriteII5 control supports multithreading

Then I have done some tests on my project. The project mainly compares two different CVS files. There is only one answerfile and one examfile for each student
I have used multithreading for testing. I have opened 10 threads, and one thread has read 500 times. If something happens, there will be an address error. After searching the data, there is no discovery, so I want to ask

core code like:
//Open
AAnswerXLS := TXLSReadWriteII5.Create(nil);
AAnswerFile := AAnswerPath + ASheetName + '.csv';
ImportCSV(AAnswerXLS, 0, 0, 0, AAnswerFile, ',', True);
AAnswerSheet := AAnswerXLS.Sheets[0];

AExamXLS := TXLSReadWriteII5.Create(nil);
AExamFile := AExamPath + ASheetName + '.csv';
ImportCSV(AExamXLS, 0, 0, 0, AExamFile, ',', True);
AExamSheet := AExamXLS.Sheets[0];

//Read like this
function XLSPreciseReadCell(ASheet: TXLSWorksheet; Row, Col: Integer): string;
var
CellType: TXLSCellType;
begin
Result := string.Empty;
Col := Col - 1;
Row := Row - 1;
CellType := ASheet.CellType[Col,Row];
if CellType <> xctNone then
begin
Result := ASheet.AsString[Col,Row];
end;
end;

Re: ImportCSV MultiThread

Posted: Fri Sep 11, 2020 1:11 am
by zhuhy87
larsa wrote:Hello

Probably. Please do a test.
Yesterday, I had do a test again.The result as follow:
When there are dozens of threads, each new city will execute my program 500 times, and occasionally there will be errors. 20 threads will execute 2000 times, and 100 threads will execute 10 times. The problem stack is as shown in the figure
Error stack pointing : AExamXLS := TXLSReadWriteII5.Create(nil); or AExamXLS.Free;