• C

timers

I want to abort a function call after sixty seconds...how do I do it?   This is on the NT Platform.  

I already tried using the SetTimer Call, but this doesn't abort the already called function.

thanks
mulshineAsked:
Who is Participating?
 
alexoConnect With a Mentor Commented:
Aborting a function call is possible in two different ways.

1) If the function is designed to be abortable, it should periodically test a flag (can be set using the timer routine).

2) A general function can be aborted if you start it as a thread (see _beginthread(), _beginthreadex() and functions and CreateThread() API).  You can then kill the thread externally using the TerminateThread() API.  Note that the thread will not be given a chance to perform any cleanup.

0
 
kinkajouCommented:
I created a simple application that displays a splash screen (that little screen that comes up while an application is initializing) and quits execution after 10 seconds. I used SetTimer (), displayed the splash dialog and when the call came to KillTimer () I had my over ridden KillTimer function send a call to the dialog telling it to close its self. Would that be possible in your case?
0
 
WxWCommented:
You probably send a WM_CLOSE message to the dialog box with the timer . That cannot be done with functions , because functions do not have a message loop .
0
Simple Misconfiguration =Network Vulnerability

In this technical webinar, AlgoSec will present several examples of common misconfigurations; including a basic device change, business application connectivity changes, and data center migrations. Learn best practices to protect your business from attack.

 
alexoCommented:
>> functions do not have a message loop.
Right, but they can have one.
0
 
kinkajouCommented:
The method I used does not have a message loop in a dialog but killed the dialog when the KillTimer() function was called. Much simpler than what everyone proposes. I would explain it further it mulshine thinks that it may solve the problem.
0
 
alexoCommented:
kinkajou, mulshine asked for "aborting a function", not a dialog.

0
 
meessenCommented:
You have to create a thread to be able to abort it from outside.
You would wait for the thread execution completion in normal situation or kill the thread if not yet done after 60 seconds.

Or you have to use a a variable you need to poll and you can set with the timer interrupt function.




0
 
alexoCommented:
Which is exactly what I suggested in my answer... :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.