Reinaldo,
Threads are very usefull but they are not ready yet in Harbour/xharbour
Antonio Linares wrote:Nageswararao,
Using the Windows API: ( CreateThread() )
http://msdn2.microsoft.com/en-us/library/ms682453(VS.85).aspx
Without using the Windows API:
http://en.wikipedia.org/wiki/Beginthread
Selvam is very much interested in sharing his knowledge with his peers and has been awarded as a Microsoft India Community Star in 2004
Additionally, I would recommed to everyone who wants to learn about multithreading to read more than one article. Most articles that I've read are missing some important points; so by reading several of them, you should get the whole picture. This article, for example, doesn't mention the most important aspect of multithreading: synchronization. Additionally, reading different articles provides you with different techniques and approaches.
Especially in a complicated field like multithreading, the more you know, the better it is.
reinaldocrespo wrote:Antonio/All;
Here is another example where threads could be very useful:
Suppose you have an xbrowse on a table of real time data, and while you have the browse in idle mode, someone inserts a new record to the table that pertains the data you are browsing. At the very least it would be nice to show a red dot somewhere to alert the user that he needs to refresh the browse to see newly inserted records.
So far I've been doing this with timers, but it is very inefficient and awkard at best.
This could be done with threads by having the app issue an "event" and have the browsing app listen for that specific threaded-event. ADS 9 adds support for notifications. A notification could be used on this example to inform a client application that data in a critical table has changed. The client app can then use this information to refresh the browse or turn a red dot somewhere without pausing to re-read the table every n seconds for critial updates. ie... no polling.
But ADS notifications are blocking calls (the call does not complete until a signal is received) therefore we would need to issue a new thread to attend this notifications and act accordingly all while the rest of the app goes on processing keystokes or whatever else.
Would you or someone else mind helping a bit more on how to use the C calls for multithreads from a fw app? I'd certainly like to test event notifications with ADS.
Thank you,
Reinaldo.
reinaldocrespo wrote:Frances;
Hi.
Threads is the natural way to consume a server message. The information about threading with xharbour is somewhat shady or at least confusing to me. Fortunately I "discovered" a way to listen to ADS server messages w/out spawning a new thread. Although it works for me (at least for now), I will eventually want to experiment with threads from xharbour. I will appreciate any info you finally come up with. Here is my trick:
sp_WaitForEvent() allows a client to synchronously wait for an event notification to be sent by the server. If an event notification for the specified event has already been sent, then this will return immediately (and that is the heart of my trick). In other words, the event notification does not have to occur while this procedure is actively waiting. This means that an application can check for an event periodically and use a small (or zero) timeout period. I set a fw-timer that executes the ADS stored procedure sp_WaitForEvent() with zero timeout period.
In a nutshell, I'm polling every x seconds for the event message. Once the message is received, I then trigger the desired action.
I've learned to look for ways to solve problems and sometimes I simply figure a work-around. I know this is not exactly what we are looking for, but for now it yields the desired results. I hope this helps.
Take care,
Reinaldo.
...
created another ADS handle for the event notification
...
update trigger has been created to table.. ' EXECUTE PROCEDURE sp_SignalEvent('tablename', FALSE, 0);'
...
Set( _SET_BACKGROUNDTASKS, .T. )
...
nTask := HB_BackGroundAdd( {|| uEvent() }, 5000, .F. ) //add to background task,
...
HB_BackGroundActive( nTask, .T. )
...
created 'EXECUTE PROCEDURE sp_CreateEvent( 'tablename', 0 );'
...
function uEvent()
created 'EXECUTE PROCEDURE sp_WaitForAnyEvent(0,0,2)'
...
here after the sp_WaitForAnyEvent ends..
how can I call a UDF? or how to know EventCount or EventName?
return
procedure RodaTabelas()
Local i := 0, aDbfs := {}, cTime := Time()
aAdd(aDbfs,"ESTOQUE")
aAdd(aDbfs,"CAIXA")
aAdd(aDbfs,"PEDIDOS")
aAdd(aDbfs,"TITULOS")
//-- Open my DBFS and return an array with the Alias of each opened
aDbfs := OpenDbfs(aDbfs)
if .not. aDbfs[1]
Dbcloseall()
Return nil
end
For i := 1 to Len(aDbfs)
StartThread({||RodarDbf(aDbfs[i])})
end
WaitForThreads()
Msg("Rodou todos!;Tempo: " +AllTrim(Str(TimeFromStart(cTime))))
Return nil
Procedure RodarDbf(cDBF)
Select(cDbf)
DbGoTop()
While !Eof()
DbSkip()
end
Return
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 26 guests