Solved

timers

Posted on 1998-06-05
8
183 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:mulshine
8 Comments
 
LVL 2

Expert Comment

by:kinkajou
ID: 1251121
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
 
LVL 11

Accepted Solution

by:
alexo earned 30 total points
ID: 1251122
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
 
LVL 6

Expert Comment

by:WxW
ID: 1251123
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
 
LVL 11

Expert Comment

by:alexo
ID: 1251124
>> functions do not have a message loop.
Right, but they can have one.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 2

Expert Comment

by:kinkajou
ID: 1251125
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
 
LVL 11

Expert Comment

by:alexo
ID: 1251126
kinkajou, mulshine asked for "aborting a function", not a dialog.

0
 
LVL 1

Expert Comment

by:meessen
ID: 1251127
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
 
LVL 11

Expert Comment

by:alexo
ID: 1251128
Which is exactly what I suggested in my answer... :-)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now