[Gambas-user] how to make threats

Fabien Bodard gambas.fr at ...626...
Wed Nov 13 21:38:58 CET 2013


The loop i use for gb.map is defferent

I have an array of 4 httpserver. Then i have an array of n files to download


--> get a free client
 Private Sub GetClient() As HttpClient

  Dim i As Integer

  For i = 0 To $aClients.max
    If $aClients[i].Status = Net.Inactive Then Return $aClients[i]
  Next

End


Public Sub tmrGet_Timer()

  Dim sUrl As String
  Dim hClient As HttpClient

  Do
   if MyArray.Count = 0 then Return
   hClient = GetClient()
   if hClient = Null then Return
   sUrl = MyArray.Pop()
   hClient.Url = sUrl
   hClient.Get(Null, $sPath &/ File.Name(sUrl))
   hClient.Tag = sUrl
loop

END

Public Sub Client_Finished()

  $TmrGet.Trigger

End



To Launch the process :

tmrGet.Trigger


so with that until all the files in MyArray are not loaded the loop
continue. A call to trigger fight the timer only time by event loop so
it not freeze the app.

if many call to timer is done at the same time only one is fight by event loop.

I use that also to refresh the map during effect animation.



2013/11/13 Sebastian Kulesz <sebikul at ...626...>:
> I had the same problem, you can look at my solution here [0]. Basically, i
> used a pool of HttpClients with the async property set to True.
>
> The logic goes like this. I have an index files which tracks around 120
> files stored online. Not going to get into how i update each file without
> downloading the rest, but suppose i want to download all files to build a
> local copy. By default, i create an array of 10 HttpClient instances. With
> DEFAULT_CLIENT_COUNT you can set it to be more.
> I then load each URL into a queue and start a timer which runs every 10 ms.
> In each run, the timer checks for a free HttpClient instance, if there is
> one it loads it with the popped  URL and saves the file into a predefined
> folder with the same name as it was stored in the server. It runs until the
> queue count is 0.
>
> You could use tasks, but i found this to be better as it is easier to keep
> track of the progress.
>
>
>
> [0]
> http://bazaar.launchpad.net/~sebikul/mundus/trunk/view/head:/.src/Index.module
>
>
> On Wed, Nov 13, 2013 at 5:05 PM, PICCORO McKAY Lenz
> <mckaygerhard at ...626...>wrote:
>
>> Tobias respond me this in another topic:
>>
>> From: Tobias Boege <taboege at ...626...>
>> > Subject: Re: [Gambas-user] wait vs sleep confusion, console works,
>> >
>> > Ahh. Actually, there is no "main thread" or something. Gambas is single-
>> > threaded throughout. In GUI programs, the so-called "event loop" kicks in
>> > automatically because you have windows open. See the docs[0].
>>
>> That its a bad notice for me.. i think about simulate that multithread
>> by making separate projects and call each then complied as EXECT AS
>> PROCESS etc etc.. this can work as expected? but i dont know how to
>> manage multiple projects inside one in the ide!
>>
>> > You can also
>> > force the event loop to run by putting
>> >
>> > While True
>> >   Wait 2 ^ 30
>> > Wend
>> >
>> yeah that's basic men, but my program its a daemon that must
>> downloading several files parallel, so with this loop only acepts one
>> event per loop (either if i use wget as process and manage such)
>>
>> > BTW: Gambas is a nice language. You cannot make threats with it :-)
>> yeah i like very much gambas, not for easy, DUE ITS NOT PORTED TO GUINDOWS!
>>
>> > Threads are also not possible in Gambas currently. (You should look up
>> the word
>> > "threat" in a dictionary.) The closest thing you can have is "Task" but
>> > I've
>> > no experience with this.
>>
>> where i find examples about taks in gambas?
>>
>> >
>> > Regards,
>> > Tobi
>> >
>>
>> --
>> Lenz McKAY Gerardo (PICCORO)
>> http://qgqlochekone.blogspot.com
>>
>>
>> ------------------------------------------------------------------------------
>> DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
>> OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
>> Free app hosting. Or install the open source package on any LAMP server.
>> Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
>> http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
> OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
> Free app hosting. Or install the open source package on any LAMP server.
> Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
> http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



-- 
Fabien Bodard




More information about the User mailing list