Obviously you'll have to stop writing sequential code and go event-
based since everything is now based on the DataAvailable (DA) event.
(If you want to keep on using sequential code you'll have to settle
with Poll, really.)
Add a property "LastStep" to your window or other class and then in
the DA event:
<As long as I haven't received the complete results: exit DA>
Select Case LastStep
Case 1 // the first query was sent and here's how to work with the
result:
<do something with the result>
LastStep = 2
<send query 2>
Case 2
<do something with the result of query 2>
LastStep = 3
<send query 3>
And so on.
Only your first query needs to be sent from outside the DA event.
And after that the code above is nearly the same as sequential
writing, nothin' much to it.
Cheers,
Marc
On Apr 19, 2007, at 1:59 PM, Guillermo wrote:
> No, this isn't the problem, read the whole thread. I have to send
> several commands to the server in each method (hundreds of method) and
> the method can't continue until the answer has been received. Imagine
> a kind of database server:
>
> SQLExecute("select ....") -> call to the server and waiting answer
> while SQLMoreRecords
>
> SQLExecute("select ....") -> call to the server and waiting answer
>
> wend.
>
> SQlExecute -> call to the server and waiting answer
> SQLSelect -> call to the server and waiting answer
>
> ... and so on....
>
>
>> There is no more waiting loop:
>>
>> 1. user clicks <send> button (or whatever)
>> 2. disable interface
>> 3. send query
>> 4. the dataAvailable event does its thing and gathers the complete
>> result
>> 5. when it's sure it has all data it displays it (or whatever is done
>> with the data)
>> 6. enable your interface
>>
>> Marc
>>
>> On Apr 19, 2007, at 12:19 PM, Guillermo wrote:
>>
>>> I have no problem disabling the interface while I wait for the
>>> result,
>>> the problem is how not eat a lot CPU cycles doing nothing in the
>>> waiting loop.
>>>
>>> Guillermo
>>>
>>>
>>> 2007/4/19, Marc (aliacta.com) <[EMAIL PROTECTED]>:
>>>> I guess the ultimate workaround is simply to disable the whole
>>>> interface, windows and menus, while you wait for the result...
>>>>
>>>> Marc
>>>>
>>>> On Apr 19, 2007, at 10:33 AM, Guillermo wrote:
>>>>
>>>>> 2007/4/19, Marc (aliacta.com) <[EMAIL PROTECTED]>:
>>>>>>> Ask Marc at Aliacta .... it can be done but it's a fair bit of
>>>>>>> work.
>>>>>>
>>>>>> Yeah... a substantial amount of work...
>>>>>>
>>>>>> If I understand Guillermo, the way pgSQL4RB works isn't what he
>>>>>> wants
>>>>>> though. He literally wants no code execution while waiting for a
>>>>>> result, yet without wasting CPU.
>>>>>
>>>>> Exactly, I need something like the "WaitNextEvent" in the old
>>>>> Mac OS
>>>>> API but for Socket, that waits for a Socket Event without
>>>>> trashing CPU
>>>>> time.
>>>>>
>>>>> I have my app nearly finished but consumes a lot of CPU waiting
>>>>> for
>>>>> packets, this is a big problem on laptops running on battery
>>>>> power.
>>>>>
>>>>> I don't know if would be possible to use semaphores for this
>>>>> matter, I
>>>>> tried it sometime ago but I didn't find a reliable method.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>