Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to write and execute a thread

I have never worked with threads before, and now I'm trying to create a thread with a query to check database status. The query is as follows:

select (*) as DBCount from v$datafile where status in 'OFFLINE';.

This query returns the total number of all the databases that are offline. Now I want to create a thread in Delphi that will execute this query in the background of my application when I run it and display the results on a label.

like image 823
Monica Avatar asked Sep 27 '10 06:09

Monica


People also ask

How do you execute a thread?

The start() method of thread class is used to begin the execution of thread. The result of this method is two threads that are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method).

What is thread with example?

Thread is often referred to as a lightweight process. The process can be split down into so many threads. For example, in a browser, many tabs can be viewed as threads. MS Word uses many threads - formatting text from one thread, processing input from another thread, etc.


1 Answers

Multithreading is hard. You may be better off using a simple threading framework like AsyncCalls.

Following StackOverlow threads may give you more information on how to solve your problem:

Delphi - Threading frameworks

How Do I Choose Between the Various Ways to do Threading in Delphi?

Delphi thread that waits for data, processes it, then resumes waiting

like image 146
gabr Avatar answered Oct 17 '22 14:10

gabr