我有一个设置了eoAsyncExecute ExecuteOption的查询,因此如果用户感觉它花费的时间太长或在一定的超时时间后仍无法检索到任何行,可以将其取消。
问题是,取消记录集以相同的方式将线程锁定,query.Open会这样做。 (可能必须先完成打开,然后才能取消...。)
查询可能会在正常获取期间关闭
简约示例(在单独的线程中)
qry: TAdoQuery;
Init
begin
try
qry.ExecuteOptins=[eoAsyncExecute,eoAsyncFetch,eoAsyncFetchNonBlocking]; //fetching of the data is also async,but that won't have an effect on cancelling
qry.SQL.Text='some inefficient long runtime SQL';
qry.OnFetchProgress := onFetchProgress; // to get the readable row count
qry.AfterClose:= onAfterClose; //set bFinished
qry.Open;
except
...//doesn't raise any errors if the SQL.Text is random gibberish,but that's a different issue with eoAsyncExecute
end;
end;
WaitingLoop
begin
while not (bFinished or (iReadableRows>0)) do
begin
sleep(1);
if bCancelled then
qry.Recordset.Cancel;
end;
ProcessData; //do something with the fetched data
end;
就我对该主题的研究而言,我发现2002年的forum discussion或多或少地将其视为正常行为。