Subject Re: Error Code 239 IDAPI error
From Michael <michael@abstractservices.com.au>
Date Sun, 22 Oct 2023 17:46:58 -0400
Newsgroups dbase.getting-started

Thanks Ed, Top tip. However, I do close the timer object. if you look at the task manager, I rarely use more than 30mb ram when running for hours.

Thanks for the tip.

Edward Racht Wrote:

> On 10/20/2023 8:37 AM, MichaelItaliano wrote:
> > I do run timers in the second app that checks if new records a re
> > written and then writes them to a server somewhere.
>
> There are some threads in programming concerning something similar to
> your issue - you may be interested in.
>
> ed
> --------------------------
> Re: timer class
> From        Andy Taylor <andy.taylor.1959@outlook.com>
> Date        Sat, 05 Dec 2020 04:50:37 -0500
> Newsgroups        dbase.programming
>
> Hi Gaetano,
>
>
>  > > MethodTwo
>  > Yes, I have implemented that. It seems to work but I need to launch
>  > another run in the morning to check if that affects another session
> of dBase.
>
> As I understand it each instance of dBASE should be fully encapsulated
> and effectively ignored by the others.
>
>  >> Finally, if you make the timer an object of the form AND you refer
> back to the form as the timer's parent make sure you remove the
>  >> parent reference from the timer before you close the form; otherwise
> dBASE wont release the form from memory properly.  You don't
>  >> need to do this but I usually do as it allows me to traverse all
> form objects easily using the inspector.
>  >>
>  > good tip, thanks! I have disabled the timer, but how do I remove the
> parent link?
>  > this.timer.parent = null in the onClose event handler?
>
> Yes, that removes the reference from the timer object but I would also
> do this.timer = null form the form because I'm anal about it.
>
>  > by the way, you mentioned canClose, why not onClose?
> Just because onClose happens after the close event and normally I don't
> want an active timer if the form has closed in case
> the timer fires when I don't want it to - say when the form is still
> closing.  In this case however, the onTimer event actually
> closes the form so the point is probably moot.
>
> I would change your code slightly to read as follows:
>
> function form_canClose()
>     this.timer.enabled = false
>     this.timer.parent = null
>     this.timer = null  // at this point the timer should release from
> memory automatically as nothing is holding it in place
>     return
>
> function form_onOpen()
>     this.timer = new Timer( ) // Make timer a property of the form
>     this.timer.parent = this // Assign form as timer's parent
>     this.timer.onTimer = {;this.parent.close()}
>     this.timer.interval = 13 // Fire timer every 13 seconds
>     this.timer.enabled = true // Activate timer
>     return
>