Timer Event Question

HARRY

Active Member
Licensed User
Longtime User
Hi,

A program stops from time to time with the message Error in <name of sub>. It cannot be based on user errors as he gives no input. In order to further investigate this problem, I want to be sure about the following.

After the user clicking a control a quite complicated action is taken which involves reading a picture file, making a number of scientific calculations, doing quite some drawing, ending in a form refresh.

During this process a timer may raise a tick event (to get GPS information update). Can I be sure that that the process of handling that tick event is postponed until all processing as a result of the user clicking a button is completed?

In the process of handling the user clicking a button no DoEvents occur.

Harry
 

HARRY

Active Member
Licensed User
Longtime User
Hi Andrew,

Thanks for your suggestion. Meanwhile I have implemented also your exception library for the two subs where these errors occur. Now I hope that the problem shows up. Sometimes it runs well for hours, but it can also happen two times in a quarter.

Harry
 

mjcoon

Well-Known Member
Licensed User
During this process a timer may raise a tick event (to get GPS information update). Can I be sure that that the process of handling that tick event is postponed until all processing as a result of the user clicking a button is completed?

If you are concerned that the timer-tick action may alter some data that is being alerady operated upon, so producing an inconsistent result, I suggest that you protect it explicitly. Presumably (!) it is not difficult to set a global boolean at the start of the button operation, and cancel it at the finish. Then if a tick event finds the boolean set either the event is ignored (if another tick will subsequently substitute) or some separate flag is set to indicate a postponement.

Typically it was useful, if going to the operating system to fetch data, to be able to accept interrupts such as timers in the interim. This makes it possible to arrange a timeout so that a slow fetch does not hang the program.

Mike.
 

agraham

Expert
Licensed User
Longtime User
Presumably (!) it is not difficult to set a global boolean at the start of the button operation, and cancel it at the finish.
My code fragment above shows this?
interrupts such as timers.
A Timer is not an interrupt. It is a subroutine call from the Forms' message loop. As such it cannot interrupt anything unless the message loop is re-entered. DoEvents re-enters the message loop and can cause re-entrancy problems under some circumstances. Displaying a message box also runs a message loop as the message box, although modal, takes over pumping messages while it is displayed. You can see this in the application attached. These are the only two situations that I know of where the message loop can be run during Basic4ppc code execution and so potentially cause re-entrancy problems. Using Form.Refresh redraws a Form to, say, update a Textbox while running a long loop but calls the Forms' Paint event directly and so does not actually run the message loop and can't cause problems.
 

Attachments

  • msgbox.sbp
    814 bytes · Views: 222
Top