1
0
Эх сурвалжийг харах

Stop cover worker before clearing books

Bernardo Magri 4 сар өмнө
parent
commit
52a510cd19

+ 5 - 0
src/bookcollection.pas

@@ -32,6 +32,9 @@ end;
 
 implementation
 
+uses
+  unitCoverWorker;
+
 { TBookCollection }
 
 procedure TBookCollection.Clear;
@@ -39,6 +42,7 @@ var
   i : Integer;
   book : TBook;
 begin
+  CoverWorkerStop;
   for i := mList.Count - 1 downto 0 do
   begin
     book := TBook(mList[i]);
@@ -81,6 +85,7 @@ destructor Tbookcollection.Destroy;
 var i:Integer;
     book:TBook;
 begin
+  CoverWorkerStop;
   for i:=0 to mList.Count-1 do
       begin
         book:= (TBook(mList.Items[i]));

+ 25 - 0
src/unitCoverWorker.pas

@@ -20,6 +20,9 @@ procedure CoverWorkerEnqueueBookIfMissing(B: TBook);
   queue is empty. Call again later to restart if you enqueue more books. }
 procedure CoverWorkerStart;
 
+{ Stops the background worker and clears any pending books }
+procedure CoverWorkerStop;
+
 implementation
 
 type
@@ -179,6 +182,28 @@ begin
   end;
 end;
 
+{ Stops the worker and clears any queued books }
+procedure CoverWorkerStop;
+var
+  l: TList;
+begin
+  if GWorker <> nil then
+  begin
+    GWorker.Terminate;
+    GWorker.WaitFor;
+    GWorker := nil;
+  end;
+  if GPdfQueue <> nil then
+  begin
+    l := GPdfQueue.LockList;
+    try
+      l.Clear;
+    finally
+      GPdfQueue.UnlockList;
+    end;
+  end;
+end;
+
 {--- worker --------------------------------------------------------------------}
 
 procedure TCoverWorker.DoApplyCover;