Urltask(), urltaskstatus and info("urltaskinfo")

I would like to use urltask() in my .Initialize procedure. The first thing I want to do is check if there is an internet connection. I see that I can use urltaksstatus statement but Im not sure how to use it. Basically I would like it to first check for a connection, the response from the server will be “connected”. If there is no response after a determined period of time I would like to display a message “Not connected to the Network”. If the response from the server is “connected” I would then like to do a series of Urltask() procedures to initialize variables with the response from the server.

How can I construct this? Can I nest a series of urltask() functions? Or how can I know when one urltask() function is done so I can then do another one? How can urltaskstatus be used in the first network check?

To check for an internet connection you could use the ipaddress statement. Check the Help file.

The urltaskstatus function can only be used in the completion code for a urltask( function. You can’t use it anywhere else. The usage is described in the Internet Errors section of this page.

The urltask( function is very nice because it allows your program to continue running while internet access occurs in the background. The flip side is that it is a lot more complicated to use, because you don’t know when (or if) the internet access will be finished. So doing a series of urltask( functions one after the other is pretty tricky. You might be better off just using the url( function.

Or at least, get your task working with the url( function, then you can try converting to urltask(.

Why is urltask() preferred over url() other than it is asynchronous?

It actually isn’t “preferred.”

It’s really your choice, depending on whether the solution to the given problem needs the task to be performed synchronously or an asynchronously. :slight_smile:

1 Like

That is the only reason.

When you use the url( function, everything stops until the transfer from the server is complete. If that only takes a tenth of a second, no big deal. But what if for some reason the connection is slow and it takes 3 seconds, 6 seconds, 20 seconds? During that time, Panorama is hung. You can’t do anything – click on buttons, type, choose a menu, etc. (By the way, if the computer has no internet connection at all, the url( function will complete and return with an error immediately.)

If you use the urltask( function, Panorama stays active while the internet transfer is taking place. You can click on buttons, type, etc. all while the internet connection is happening in the background.

A common use of the url( function is to retrieve text from the web, then do something with that text, like this:

local webpage
webpage = url(...)
dosomethingwith webpage

In the example above, by the time the program gets to the third line you know that either the webpage variable contains the text, or there was an error. But you can’t use urltask( that way, because the data isn’t available until later. See Running Code After the Data is Downloaded (on the urltask( page) to learn the correct way to do something with data you download with the urltask( function.

One place where Panorama X uses the urltask( function is in the Site License wizard. This wizard contacts the ProVUE server to log on, log off, make payments, check history, etc. All of these operations are done with the urltask( function so that Panorama X doesn’t freeze while waiting for the server. It made the wizard more complicated to write, but I think it was work the extra effort, at least in this case. If I’m doing something quick and dirty, I’ll usually just use the url( function.

Jim

Very interesting, I have a series, at this point 7 urltask() in one procedure. All use the same variable for the formula and the same variable for the result. Then in the “code” section I assign the results to a different variable in all 7 and it works. It looks like this.

vFormula=“Some Formula”

vTaskID=urltask(“the Url”,“var”,“vDBcgiReults”,“post”,initialize dictionary("",vFormula),“code”,{vResult1= vDBcgiReults show variables vResult1})

And I repeat this 7 times using vDBcgiReults and vFormula.

How does urltask() keep those variables, vDBcgiReults and vFormula, straight?

It all seems to work well.

I don’t think it is keeping them straight. As long as there is enough time elapsed for you to do

vResult=vDBcgiResults

before the next reply comes in, you don’t have a conflict. vDBcgiResults is passing those results off like a hot potato.

I don’t know why you aren’t putting those results directly into vResult1, instead of transferring. I think that would eliminate all concerns.

Dave

Hi Dave, I am actually putting them into vResult1 for the first urltask(), vResult2 for the second, vResult3 for the third etc. So vDBcgiResults is passing off its value to different variables in each of the 7 urltask()'s. Will that make a difference?

That’s what I assumed you were doing. I just don’t know why you don’t cut out the middle man, and have urltask( put it directly into vResult1 etc. I don’t see the need for vDBcgiResults at all.

Dave

Didn’t think about it, but that makes sense. So should the vFormula variable also be a different variable for each urltask()? Or will urltask() not confuse vFormula? It doesn’t currently appear to be confusing it, I am getting the expected results but before I implement this approach in other places I want to make sure I am not creating problems for myself.

It looks to me like vFormula is part of the request, not the result. Panorama won’t wait for the result to come back, but I doubt if the next statement will run before the request is sent.

Dave

I don’t understand how vFormula is being used. What is that supposed to be? You are passing it as the first POST data item, but with no key. That doesn’t make any sense.