Using Visual C++ with MFC. When a certain event occurs in my code, I want to set a function to be called 10 seconds later to perform some activity. The handling of the event happens in a static library that doesn't have any direct links to MFC (and I'd like to keep it that way).
How can I schedule a function to be called at some point in the future? Use a Timer I guess? How do I decouple the Timer (which is an MFC dependency) so my business code doesn't have a direct dependency on the GUI? Or maybe something else besides a timer?
Update
Recently started reading about the Command Pattern which seems promising for my situation. The description is (my emphasis):
In object-oriented programming, the command pattern is a design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time.
Approach 1
Write a wrapper function for the call to the static library.
Before the static-library call, do a sleep for the required duration.
Approach 2 Use a Win32 timer http://www.codeproject.com/Articles/1236/Timers-Tutorial#Win32Timers
You can avoid the MFC dependency in both approaches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With