[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Method execution with timeout

Posted on 2002-07-19
3
Medium Priority
?
237 Views
Last Modified: 2010-04-04
Greetings, all!

I want to execute some method with timeout.
Suppose there is method foo() and I want to call it and if it had't finished in specified amount of time seconds, I want to cancel it.
How do I do that? Threads I suppose?

Respectfully yours, Eugene.
0
Comment
Question by:eugenem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
swift99 earned 200 total points
ID: 7165805
The easy way is to instantiate a thread and an event, kickoff the thread, and wait for the event to be signalled.

var
  FooEvent: TEvent;

procedure MyClass.foo
begin
  FooEvent := TEvent.Create (NIL, false, true, 'FooEvent');
  MyThread := TMyThread.Create; // Assume thread immediately executes
  WaitResult := FooEvent.WaitFor (TimeLimit); // TimeLimit is integer milliseconds
 
  case WaitResult of
  wrSignalled: HandleSuccess;
  wrTimeout: HandleTimeOut;
  wrAbandoned: HandleAbandoned;
  wrError: HandleOtherErrors;
  end;
end;

In the thread, use

procedure TMyThread.Execute;
begin
  // Various business logic
  FooEvent.SetEvent;
end;
0
 

Expert Comment

by:CleanupPing
ID: 9343027
eugenem:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 9461320
eugenem,
No comment has been added lately (18 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to swift99 http:#7165805

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --

Thanks,

anAKiN
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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