hb_threadStart

Post Reply
oliveiros junior
Posts: 148
Joined: Tue Mar 20, 2007 3:13 pm

hb_threadStart

Post by oliveiros junior »

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
User avatar
ssbbs
Posts: 140
Joined: Mon Oct 17, 2005 3:03 am
Location: Taiwan

Re: hb_threadStart

Post by ssbbs »

You need to use the sharing mode when you open the file.
line ID: ssbbstw
WeChat ID: ssbbstw
oliveiros junior
Posts: 148
Joined: Tue Mar 20, 2007 3:13 pm

Re: hb_threadStart

Post by oliveiros junior »

Olá ssbbs, obrigado pela resposta.

Como seria essa abertura compartilhada. Poderia dar um exemplo?

Att.,

Oliveiros Junior
vilian
Posts: 1068
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil
Contact:

Re: hb_threadStart

Post by vilian »

Olá Oliveiros,

Seria algo assim: USE (cTab) INDEX (cIndex) ALIAS (cAlias) NEW SHARED
Sds,
Vilian F. Arraes
[email protected]
Belém-Pa-Brazil
JoséQuintas
Posts: 104
Joined: Tue Feb 09, 2021 4:20 pm

Re: hb_threadStart

Post by JoséQuintas »

oliveiros junior wrote: Tue Jun 24, 2025 11:52 pm 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:

Code: Select all | Expand

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)

oliveiros junior
Posts: 148
Joined: Tue Mar 20, 2007 3:13 pm

Re: hb_threadStart

Post by oliveiros junior »

Obrigado José Quincas.
User avatar
Lailton
Posts: 231
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil
Contact:

Re: hb_threadStart

Post by Lailton »

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
Post Reply