FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour hb_threadStart
Posts: 148
Joined: Tue Mar 20, 2007 03:13 PM
hb_threadStart
Posted: Tue Jun 24, 2025 11:52 PM

Dear all, good evening!

I am using a Thread to execute a routine for creating and indexing files (DBF), so far so good. In the same Thread I open the files, but when I close the Thread and try to use a file, I get the message that it is not open. Is there a way to get around this?

Thank you in advance for your attention!

Oliveiros Junior

Posts: 129
Joined: Mon Oct 17, 2005 03:03 AM
Re: hb_threadStart
Posted: Wed Jun 25, 2025 02:06 AM

You need to use the sharing mode when you open the file.

line ID: ssbbstw

WeChat ID: ssbbstw
Posts: 148
Joined: Tue Mar 20, 2007 03:13 PM
Re: hb_threadStart
Posted: Wed Jun 25, 2025 02:51 PM

Olá ssbbs, obrigado pela resposta.

Como seria essa abertura compartilhada. Poderia dar um exemplo?

Att.,

Oliveiros Junior

Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: hb_threadStart
Posted: Wed Jun 25, 2025 05:15 PM

Olá Oliveiros,

Seria algo assim: USE (cTab) INDEX (cIndex) ALIAS (cAlias) NEW SHARED

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 104
Joined: Tue Feb 09, 2021 04:20 PM
Re: hb_threadStart
Posted: Wed Jun 25, 2025 08:28 PM
oliveiros junior wrote: I am using a Thread to execute a routine for creating and indexing files (DBF), so far so good. In the same Thread I open the files, but when I close the Thread and try to use a file, I get the message that it is not open. Is there a way to get around this?
No.
This is harbour default, and it is the best way to use multithread.
Each thread is like an EXE.
Files are opened on one thread, not on another.
On multithread you can use CLOSE DATABASES and only DBF on that thread will be closed.

I do not make full use of fivewin, may be code is wrong:
USE ARQ1 SHARED
hb_ThreadStart( { || test() } )
browse()
CLOSE DATABASES
...
FUNCTION Test()

USE ARQ1 SHARED
browse()
CLOSE DATABASES
RETURN Nil
You will have 2 browses, one on each thread, file need to be opened on each thread, alias on one thread is not visible on another, you can use same alias for any file.
CLOSE DATABASES will close only file on that thread.
The best: you can change index order, record position, apply filter, and one thread do not change another.

Caution about this:
Create dialog on one thread and run on another thread is not the same as make all on same thread.

José M. C. Quintas Brazil

gtwvg, fivewin 25.12, hwgui, mingw 15.2 (32 bits)

Posts: 148
Joined: Tue Mar 20, 2007 03:13 PM
Re: hb_threadStart
Posted: Thu Jul 03, 2025 05:10 PM

Obrigado José Quincas.

Posts: 231
Joined: Fri Jul 20, 2012 01:49 AM
Re: hb_threadStart
Posted: Thu Jul 03, 2025 05:49 PM
Fala Junior,

Harbour MT tem as WORKAREA separado, cada thread tem sua propria WORKAREA.

Eu costumo abrir o banco de dados dentro da minha thread, faco o que precisa e automaticamente quando a thread finaliza, ela ira liberar o workarea ( dbCloseArea() ).

Voce pode abrir o mesmo DBF em varias thread pois sao totalmente individualizado.

Nota:
Existe mandeira de compartilhar, se nao me engano tem os comandos hb_dbRequest e hb_dbDetach que permite fazer uns paranaue
porem deixa so mais complexo.

:D
Regards,

Lailton Fernando Mariano

Continue the discussion