🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.pascal.delphi.databases
2 messages
2 total messages Started by Chris Moseley Wed, 13 Jan 1999 00:00
Background thread writing to DB - dealing with app shutdown
#74
Author: Chris Moseley
Date: Wed, 13 Jan 1999 00:00
34 lines
2023 bytes
Hi all. 

I have a background thread writing a (selective) log of user 
activity to a table for audit purposes. On occasion this will
receive a significant number of entries just before the app 
terminates (the user goes "yup, save all of those, I'm done").

At this stage the UserLog unit creates/starts and frees the
thread in the initialization/finalization sections, but
this causes AV's if the thread is active when the app 
terminates - it looks as if the memory used is free'd from 
underneath the thread.

Questions:
1: does code in the finalization block actually have to
   complete before the app shuts down? I've assumed so.
2: It looks as if the app does not wait for my thread to 
   terminate. Correct?

What's the best way around this?
- terminate the thread then write any remaining entries from
  the main thread.
- do that but using the database and query owned by the thread
- sit in a loop polling the buffer until it's empty, then 
  exit the finalization block?
- do something else. Any ideas?

The other thing I've thought of doing in making the thread 
depend on the main form - put the start/stop into the form
create/free. Does this sound reasonable?

Thanks
Moz
Re: Background thread writing to DB - dealing with app shutdown
#75
Author: John smith
Date: Tue, 12 Jan 1999 00:00
37 lines
2074 bytes
Strange, it works for me. Maybe the thread object references something in
main form (or other) or it creates a component with application as owner. If
this is the case, then your main form should wait for other threads to
complete before closing.
ad1: No. Application shut down=main thread shuts down, but OS does not
unload process until all threads complete (at least I think so).
ad2: Yes, that's correct.

--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.cerny@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.
Chris Moseley wrote in message <369BBB1F.A581D919@acs.co.nz>...
>
>Hi all.
>
>I have a background thread writing a (selective) log of user
>activity to a table for audit purposes. On occasion this will
>receive a significant number of entries just before the app
>terminates (the user goes "yup, save all of those, I'm done").
>
>At this stage the UserLog unit creates/starts and frees the
>thread in the initialization/finalization sections, but
>this causes AV's if the thread is active when the app
>terminates - it looks as if the memory used is free'd from
>underneath the thread.
>
>Questions:
>1: does code in the finalization block actually have to
>   complete before the app shuts down? I've assumed so.
>2: It looks as if the app does not wait for my thread to
>   terminate. Correct?
>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads