Threads and timers, how to manage multiple?

What kind of dirty, ugly and nasty alternatives do you use when managing many threads and timers in a project!?
What is the kind, with minimum of code and generate most offensive answers on this forum as you can think of!?
It’s the kind I’m looking for…

I always found it very offensive if the answer to a question is one word, so I’m trying: DelegatingTimer.

Thank you!

Well.
I’m a nice person! No harm!
I mean, I do not want an essay of miles of code… It’s all!
Something that works without the hassle of being “by the book”.

Maybe it was the bad English from me!? Excuse me if so!

Grin… don’t know about english. But offensive means:

The label Offensive is used in this dictionary to indicate that a particular term or definition is likely to be perceived as insulting by a listener or reader—an affront to that particular individual or to an entire group of like individuals—whether or not an offense was intended. Offensive is often paired with the label Disparaging used to indicate that those people who use the offensive term do so to offend intentionally.

Anyways: search for something called DelegatingTimer. Or have a look at this thread: https://forum.xojo.com/8120-sharing-a-timer-between-multiple-windows/0

[quote=163323:@Jakob Krabbe]What kind of dirty, ugly and nasty alternatives do you use when managing many threads and timers in a project!?
What is the kind, with minimum of code and generate most offensive answers on this forum as you can think of!?
It’s the kind I’m looking for…[/quote]

What do you want to achieve, exactly ? I seldom see apps that need MANY threads…

I would want to ask what you management is needed?
If you need a timer somewhere, put it on a window or create in code, let it fire it’s action and switch it off when no longer needed.

Oh, dear…!
I rarely regret things these days, but this thread I could sure live without! :slight_smile:

I have a small sync application, that will sync information from one website to another.
I have fiddling with this issue for three weeks. All parts work one by one but not together…

It happens, when you send too many requests to a web server, the server sort of think DOS or DDOS… I think, it’s the main problem. Too many requests in too short time space.

So… I need to make everything much slower. In an attempt to achieve this, more than one thread is one alternative. However, I may solve it anyway. For now, this tool is only for me, but eventually these things will also be on the client… I think… But lately, I’ve thought of alternative, much slower, solutions that may also work.

[quote=163551:@Jakob Krabbe]Oh, dear…!
I rarely regret things these days, but this thread I could sure live without! :slight_smile:

I have a small sync application, that will sync information from one website to another.
I have fiddling with this issue for three weeks. All parts work one by one but not together…

It happens, when you send too many requests to a web server, the server sort of think DOS or DDOS… I think, it’s the main problem. Too many requests in too short time space.

So… I need to make everything much slower. In an attempt to achieve this, more than one thread is one alternative. However, I may solve it anyway. For now, this tool is only for me, but eventually these things will also be on the client… I think… But lately, I’ve thought of alternative, much slower, solutions that may also work.[/quote]

Have you been using HTTPSocket ? If so all you have to do is send a get and wait for the PageReceived event to take place before sending a new request. Event driven apps are much better than timer paraphernalia.

Why do you regret asking? It’s always good to have options. In Windows I like to have separate timers. In classes I use the DelegatingTimer.

Most likely Michel is correct and you need to think about how to makes things work together. And I hate this sort of stuff, too.

http://documentation.xojo.com/index.php/HTTPSocket.PageReceived

Hmmm!
Interesting, indeed! May I use PageReceived in a FOR … NEXT loop? Without the need for and/or the timer, the delay!?
It would be the best, really!! That will save me much code and much headache! :slight_smile:

But, there are no code example on this page. How does it work?

DIM strPage = "www.mywebsite.com/open.asp?ID=123&score=42"

How would such line fit in the PageRecieved event?

[quote=163562:@Jakob Krabbe]http://documentation.xojo.com/index.php/HTTPSocket.PageReceived

Hmmm!
Interesting, indeed! May I use PageReceived in a FOR … NEXT loop? Without the need for and/or the timer, the delay!?
It would be the best, really!! That will save me much code and much headache! :slight_smile:

But, there are no code example on this page. How does it work?

DIM strPage = "www.mywebsite.com/open.asp?ID=123&score=42"

How would such line fit in the PageRecieved event?[/quote]

One way I do it is :

  • Insert Class
  • Make Class1 super HTTPSocket
  • Drag an instance of Class1 over a window ; call it what you want, for instance http
  • You can now add events to that instance. At the minimum Error and PageReceived

Then in that window, you can request a page from the web site. When the page has been served by the site, it will be available in PageReceived Content property.

With that, you do not use timers. You write your code in two places : a place where you request the page, and in the PageReceived event.

I usually use it asynchronously, so it does not freeze the UI. See http://documentation.xojo.com/index.php/HTTPSocket

Magic!!
I don’t really understand much of this, but I shall really try, because it seems awesome!! Quite useful for me!

Yes! It works and seem really good, so far!
But…! How do I use it!?

What code do I write and how do I trigger the code!?

  • Error = ??
  • PageReceived = ??

Do I need to think of an example code to include or can you imagine something out of the blue, that might be useful for me…?
Or, just use the one already written:

DIM strPage = "www.mywebsite.com/open.asp?ID=123&score=42" DIM i as integer FOR i = 1 TO 500 updateServerURL ( strPage ) NEXT

What exactly do you want to obtain ?

You got a good example about how to get a page from a site at http://documentation.xojo.com/index.php/HTTPSocket

Hello world!! :slight_smile:

Yes… you might think it’s clear and so much obvious! In your eyes!
But for me, the fog is quite present…

The text on the page only reads, “use it”! But for me, that’s no help. How do I use it!?

I want to load many URL’s in a row, as described above. I wrote 500 as an example of “very many requests”, not typical 500 requests.


I never found any actual example code, neither on the docs -pages, in my two books or elsewhere.
Just “use it”, might come as a surprise to you, but for me, it’s not enough to do the work! For me, I need little less conversation, little moire action! :slight_smile:

Sorry for being such demanding dude! I do my best and I know, it’s not always good enough! :slight_smile:
I rest my case, move on and find something else.

Excuse me!
It’s not the Answer.
Can someone with admin access please “un-answer” the above post. I intended to “EDIT”, not “MARK AS ANSWER”.

I also find this forum interface some how confusing and un-logic… and I’m waiting for the creator to join me in this impression! :slight_smile:

Well. The customer is always right — but not all the time.

[quote=164016:@Jakob Krabbe]Excuse me!
It’s not the Answer.
Can someone with admin access please “un-answer” the above post. I intended to “EDIT”, not “MARK AS ANSWER”.

I also find this forum interface some how confusing and un-logic… and I’m waiting for the creator to join me in this impression! :slight_smile:

Well. The customer is always right — but not all the time.[/quote]

You can change the answer by clicking another post anytime.

That is not descriptive enough to really help. What do you mean by “load” ? You want to get the content of a URL in a variable ? It is described at the link about httpsocket, in the get method. Here is an example :

In a button :

Sub Action() http.Get("www.xojo.com") End Sub

In the PageReceived event :

msgbox content

When you click the button, the page www.xojo.com is called, just like if it where entered in a browser URL bar. After a second or two, the page has been received, and it’s content is available in http.PageReceived

If you want to fetch several pages, you must treat them as a queue ;

httpsocketqueue.xojo_binary_project

The string property array URLs() contains all the URL to fetch
The integer property URLIndex keeps track of the URLs to get

This project gets the content of 5 pages and puts it in the listbox, but you can get hundreds if you want and save that to a database or whatever you want. It should help you better understand.

Neat!
Thank you!
Now we’re getting somewhere! :slight_smile:


In my project I already have an array that can be used also for this purpose. (I should have.)
I now need to do some testing to make it fit my needs! But sure, I’m half way through!!

I lift my hat!
Thank you!

Fellow dudes & dudisses!

I have some questions related to the above issue:
The http connection works good “as is”, so to say. Now I need to include the feature in my current environment…

My current environment, my situation, includes much database reading, inserting and checking. Simply, a great deal of commit-ments! :slight_smile:

My question is, where do I put all this action!? inside the http- connection or do I call a Method doing the work independently…?
The URL’s as I use are not the same… in the sense, they do not contain the same information.

Would it be wise to open the database inside the http- connection and doing the fiddle in the connection moment!?

Excuse me for the bad English! Maybe someone can understand my idea, the question, with the assistance of some home made imagination…?

Excuse me for being slow, but there is something wrong with the logic in this code…
I still don’t understand how it really works! For me, it still doesn’t work. It’s either too fast or too slow.
The code is not waiting for the response.

In the button: URLs(1) = "http://www.syscare.se" URLs(2) = "http://www.syscare.se" URLs(3) = "http://www.syscare.se" URLs(4) = "http://www.syscare.se" URLs(5) = "http://www.syscare.se" URLIndex = 1 http.Get(URLs(URLIndex))

In the http.pageRecieved:[code]

ListBox1.addrow(Content)
TextArea1.AppendText content + EndOfLine

Label1.Text = str(URLIndex)

if URLIndex <6 then
System.DebugLog str(URLIndex) + " >> " + URLs(URLINdex)
System.DebugLog "URL " + url
System.DebugLog "httpstatus " + str( httpStatus )
System.DebugLog "headers " + headers.Name(0)
System.DebugLog "headers " + str( headers.Count )
DIM i as Int16
FOR i = 0 TO headers.Count -1
System.DebugLog "headers loop: " + headers.Name(i)
NEXT
'System.DebugLog "headers " + headers.NameCount(0)
System.DebugLog "content: " + content

Label2.text = URLs(URLINdex)

me.Get(URLs(URLIndex))
URLIndex = URLIndex + 1

end if[/code]


I’ve added some code… However:

  1. Why are there two loops? One in the button and the second loop in the http.PageRecieved code?
  2. If I call the pageRecieved cod inside the loop, in the button, it doesn’t work. It’s too fast.

I’d like to add, I enclose this working test code while as the my own project code is too complex to explain and to include in this forum window. But the idea is the same. I collect (save) addresses (URL’s) in a loop, add to an array and then go through this array…


In my IRL project, there is no need to fiddle with the result, i.e. “content”. I added this, the “content” to the TextField1 because I got the impression the function is waiting for the content to arrive and then trigger the next part, after arrival.