Recent

Author Topic: OnEndSession(  (Read 5949 times)

dbannon

  • Hero Member
  • *****
  • Posts: 3667
    • tomboy-ng, a rewrite of the classic Tomboy
Re: OnEndSession(
« Reply #15 on: May 03, 2019, 12:29:32 pm »
....
Use a timer with 10 seconds tic
....
So you loose only 10 seconds of your work if the app crashes or the system goes down.
Yes winni, that works but there is a risk. Firstly, if the user powers down while that save is taking place, its a bad thing. Sure, on Linux, there is a good chance you are using a journaled file system but I hate depending on journal. And if they are, for some reason, not using one of the journaled filesystems, the whole data file is probably trashed. So, maybe safest approach is your own journal ?
When saving, save to a temp file, when its fully written, delete (or rename) the original and then rename your temp to the original name. Substantially reduces your exposure.
What really worries me with my app is that its something people leave running in the background. Like you, I set a 10 second timer to save, in that time someone can make some change and powerdown their machine, loosing the change. 

Sigh
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: OnEndSession(
« Reply #16 on: May 03, 2019, 02:02:33 pm »
The best way I've found to deal with this is to revert to the good old days beahviour: each time your data changes (whether it's true data or just configuration) just save it as securely as posible, even up to use the "self-journaling" Davo talks about.

In Linux it's very easy to forget you have a process running minimized in the fourth workarea (say, a backup task) and shutdown the computer from the first one once you think you're done. Don't laugh: it happens :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

dbannon

  • Hero Member
  • *****
  • Posts: 3667
    • tomboy-ng, a rewrite of the classic Tomboy
Re: OnEndSession(
« Reply #17 on: May 05, 2019, 03:13:50 am »
.....each time your data changes (whether it's true data or just configuration) just save .....

Yes, its relatively safe but can be quite intrusive. I use Kmemo, think of it as a bit like TMemo, as a user types into it, each key press triggers an OnChange event, if you then choose to save the contents of the memo on each OnChange, a fast typer can easily bog the system down. Once you start queuing those saves up, you start loosing the advantages of the Unix disk caching and users sees the application as 'slow'.

Saving in a separate thread would help perhaps ...
In Linux it's very easy to forget you have a process running minimized in the fourth workarea .....

Indeed ! And its not a laughing matter. My app auto saves but thats not suitable for every thing ....
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: OnEndSession(
« Reply #18 on: May 05, 2019, 04:40:58 am »
Yes, its relatively safe but can be quite intrusive. I use Kmemo, think of it as a bit like TMemo, as a user types into it, each key press triggers an OnChange event, if you then choose to save the contents of the memo on each OnChange, a fast typer can easily bog the system down. Once you start queuing those saves up, you start loosing the advantages of the Unix disk caching and users sees the application as 'slow'.

Oh, not that much frequency. With a Memo of almost any kind you can't start saving on each key press, not even in a separate thread. What you do in that case is save a copy each X minutes or in an OnIdle event, and that can be done in a separate thread so the user doesn't notice it  (at least not much!), and save the definitive when something signals the user has ended. That is the way most editors and word-processors work.

Sure, it's not as secure as saving at each minimal change but it's a lot better from the user-experience point of view

Besides, a user typing in a memo isn't likely to decide to shut-down the next second ;)
« Last Edit: May 05, 2019, 04:42:32 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Firewrath

  • New Member
  • *
  • Posts: 35
Re: OnEndSession(
« Reply #19 on: May 08, 2019, 05:17:01 pm »
Well, I hate replying to something off the front page, but blame my lack of home internet. >.>
and I really just wanted to throw this up here. :P

Yes, its relatively safe but can be quite intrusive. I use Kmemo, think of it as a bit like TMemo, as a user types into it, each key press triggers an OnChange event, if you then choose to save the contents of the memo on each OnChange, a fast typer can easily bog the system down. Once you start queuing those saves up, you start loosing the advantages of the Unix disk caching and users sees the application as 'slow'.

I've been using this for a 'search while typing' search box, so that it doesn't search large files which each key press:
Code: Pascal  [Select][+][-]
  1. PROCEDURE TForm1.Wait(dt: QWord);
  2. var
  3.   tc: QWord;
  4. BEGIN
  5.   tc := GetTickCount64;
  6.   while (GetTickCount64 < tc + dt) and (not Application.Terminated) do
  7.     Application.ProcessMessages;
  8. END;
  9.  
  10. PROCEDURE TForm1.Itm_Srch_EditChange(Sender: TObject);
  11. var
  12.   t : string = '';
  13.   l : integer = 0;
  14. begin
  15.   t := Itm_Srch_Edit.Text;
  16.   l := Length(Itm_Srch_Edit.Text);
  17.   if (Itm_Srch_Edit.Text <> '') then
  18.     Wait(750);
  19.  
  20.   if (Length(Itm_Srch_Edit.Text) = l) AND (Itm_Srch_Edit.Text = t) then
  21.   begin
  22.     <do search>
  23.   end;
  24. end;
  25.  
(iirc, the 'Wait' bit was stolen from GetMem :P)

It saved me SO MUCH 'lag' time when searching listboxs with like 20,000+ items....
(Now a TStringGrid, but I kept the code anyways, ya know, jic.)
I imagine something similar could also be used for a TMemo to prevent saves while the user is typing, and wait till they stop for a second.
...or whatever program youre working on that has constant user input.

What you do in that case is save a copy each X minutes or in an OnIdle event, ....
Also, maybe this is a me thing, but I have had such awful luck trying to get OnIdle to work that I just gave up on it. >.>
I tried to make an app that ran in the system tray and would cover the screen on idle, but I also have RainMeter running and it kept making it flash something horrible. I think cause it triggered all the time. idk, not really the thread for it, just saying. :P
Sorry. I currently don't have Internet Access. So my replies might take a week. -_-

dbannon

  • Hero Member
  • *****
  • Posts: 3667
    • tomboy-ng, a rewrite of the classic Tomboy
Re: OnEndSession(
« Reply #20 on: June 15, 2019, 04:57:36 am »
Well firewrath, my replies are even slower, thats because i have been travelling.  But don't want to leave you unanswered/unthanked.

I do something similar, in the OnChange event I trigger two timers, one gets retriggered on every Onchange and therefore does not fire until the user stops for a think (we do some housekeeping there, markup etc), the other timer will, eventually (10 seconds) always fire and that one is used to save.

But i really wanted to save (only at end session) things like window size, to be restored at startup. And it looks like I cannot !  So be it !

Thanks.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018