Re: [twsocket] Wait for

2013-01-12 Thread François Piette
 Using HTTPCLI AsyncGET how main thread wait for the Async to download 
 the html code.
 Code relies on input html code. If i sleep the main ui thread it will 
 become frozen.
 
 I know how to get HTML with Async via Events but i have no idea how 
 program it so that Main UI thread will wait and then continue.. :)

 use a timer. The HTML fetches your stuff async and stores it somewhere 
 and sets some get was successfull flag.

Defenitely not ! Use the http component OnRequestDone handler to handle what
has to be done. At most you use a timer to implement a timout feature, not
more.

-- 
francois.pie...@overbyte.be
Embarcadero MVP
http://www.overbyte.be




--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] Wait for

2013-01-12 Thread François Piette
 Using HTTPCLI AsyncGET how main thread wait for the Async to download the
html code.
 Code relies on input html code. If i sleep the main ui thread it will
become frozen.
 I know how to get HTML with Async via Events but i have no idea how
program it so 
 that Main UI thread will wait and then continue.. :)

The component has Sync methods as well? Those are based on the Async
methods (native) using a wait loop.
It is much much better to use only async methods. This requires you develop
your application with async in mind. This means you don't write code
sequentially but rather use the events.

At first glance, asynchronous programming is a little bit more difficult to
grasp, but once you get it, you'll see it is really easy and powerful? After
all, Windows UI is fully asynchronous and event driven: you never wait that
the user click on a button. Instead you handle processing in the OnClick
handler. This is exactly the same with ICS component: you start an operation
(such as a http get) and then exit your routine. When the result is coming,
you get an event triggered (OnRequestDone in the http case). Just like you
put the code to handle the click on a button in the OnClick event handler,
you put the code to process the request result in the OnRequestDone event
handler.

To correctly develop an application using the async, event driven paradigm,
you'll see that a finite state machine is a very useful pattern (See
http://en.wikipedia.org/wiki/Finite-state_machine as a starting point). To
make the story short, applied to Delphi, you define an enumerated type with
all the states of your application and then use a variable to hold the
current state. Once an event occurs, such as a http get request done, you
use that state variable to know what to do you the result and to determine
what will be the next state.

Of course, it is better to split your whole application in sub-problems,
each one with his own state machine. This is exactly what ICS components
are: state machines applied to specific internet protocols such as the http
protocol you use.

Hoping this helps.
-- 
francois.pie...@overbyte.be
Embarcadero MVP
http://www.overbyte.be



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be