Solved

timers

Posted on 1998-06-05
8
185 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 11

Expert Comment

by:alexo
ID: 1251124
>> functions do not have a message loop.
Right, but they can have one.
0
 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

803 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