Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Avoid duplicate thread creation


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Dec 12, 2016 10:41 AM Last Post By: Remy Lebeau (Te...
Toby Dobbs

Posts: 77
Registered: 9/24/16
Avoid duplicate thread creation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 7:50 AM
Hi,

I was wondering if I need to be avoid duplicate thread creation as in...

thread := TMyThread.Create(True);
thread.Resume;


...being run every time a button is clicked? If so then how should I go about this?
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Avoid duplicate thread creation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 10:13 AM   in response to: Toby Dobbs in response to: Toby Dobbs
Toby Dobbs wrote:

Hi,

I was wondering if I need to be avoid duplicate thread creation as
in...

thread := TMyThread.Create(True);
thread.Resume;


...being run every time a button is clicked? If so then how should I
go about this?

Hard to say without knowing the purpose of your thread. The simplest
way to avoid creation of a new thread is to disable the button after
the code above. But you then need a way to re-enable the button when
the thread terminates.


--
Peter Below
TeamB

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Avoid duplicate thread creation  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2016 10:41 AM   in response to: Peter Below in response to: Peter Below
Peter wrote:

The simplest way to avoid creation of a new thread is to disable
the button after the code above. But you then need a way to
re-enable the button when the thread terminates.

The thread's OnTerminate event can be used for that.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02