Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TSomeThread = class(TThread)
- private
- FAbortEvent: THandle;
- FContinueEvent: THandle;
- protected
- procedure Execute; override;
- procedure TerminatedSet; override;
- public
- constructor Create; reintroduce;
- destructor Destroy; override;
- procedure ContinueExecution;
- end;
- implementation
- constructor TSomeThread.Create;
- begin
- inherited Create(False);
- FAbortEvent := CreateEvent(nil, False, False, nil);
- FContinueEvent := CreateEvent(nil, False, False, nil);
- end;
- destructor TSomeThread.Destroy;
- begin
- CloseHandle(FContinueEvent);
- CloseHandle(FAbortEvent);
- inherited Destroy;
- end;
- procedure TSomeThread.Execute;
- var
- WaitResult: DWORD;
- WaitEvents: array[0..1] of THandle;
- begin
- // some actions before pause...
- // prepare the waiting event array
- WaitEvents[0] := FAbortEvent;
- WaitEvents[1] := FContinueEvent;
- // and block the thread for infinite time until you signal one of those events;
- // that may happen if you (or the application) calls Terminate, or if you call
- // ContinueExecution method
- case WaitForMultipleObjects(2, @WaitEvents, False, INFINITE) of
- WAIT_OBJECT_0: ; // Terminate has been called in this branch
- WAIT_OBJECT_0 + 1:
- begin
- // ContinueExecution has been called in this branch, so here you can continue
- // with your processing
- end;
- WAIT_FAILED: ; // something unexpected happened; GetLastError tells you what
- end;
- end;
- procedure TSomeThread.TerminatedSet;
- begin
- inherited;
- SetEvent(FAbortEvent);
- end;
- procedure TSomeThread.ContinueExecution;
- begin
- SetEvent(FContinueEvent);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement