Solved

Delphi events and processing

Posted on 2001-06-22
1
247 Views
Last Modified: 2010-04-06
What is the outcome when there are 2 different events calling the same procedure? will the procedure be pre-empted or will delphi create another instance of that procedure?

given:
 * 2 timers - TimerA and TimerB both enabled at the same time with the same time interval
 * 1 common procedure - Procedure Process_Data(code: string); (doing some lengthy processing)
    if code=A then process with parameter A
    if code=B then process with parameter B

sequence of events:
 * enable TimerA and TimerB
 * OnTimer of TimerA - call Process_Data('A');
   OnTimer of TimerB - call Process_Data('B');

how is the procedure going to proceed? will there be time-slicing? and if so, what are the priorities?
0
Comment
Question by:ttanyag
1 Comment
 
LVL 20

Accepted Solution

by:
Madshi earned 100 total points
ID: 6217588
Windows timers work via messages. That means, as long as you don't handle messages, no timer is fired. That again means, if the first timer is fired, your callback function is called. If you don't do any message handling in this function, the second timer has to wait (even if the time is over), until your callback function is run through. Only then (hopefully someone else now handles messages, e.g. Application.Run does) the second timer is finally fired.

Delphi doesn't copy a procedure "instance" or code. If you create 2 timers that share the same callback function, then the same function is called. However, if you use Delphi's TTimer object (instead of pure win32 API), you can use "Self" to differ between the different parent timers.

Time slicing only applies to threads. Timers are no threads. One after the other is the mode, except if you're handling messages in the timer callback function, then the second timer may be fired, while the first is not fully handled yet. But then the first timer is "paused" as long as the 2nd is not finished.

Regards, Madshi.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to send PJL commands to printer 3 99
add combobox item based on numbers 9 141
Delphi IDE crash without error message ... 7 89
Firemonkey webbrowser scrollbars ? 1 38
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question