PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WEBDEV 2024 → [WM23] How to update info of a Page with a Thread
[WM23] How to update info of a Page with a Thread
Débuté par ARV, 29 aoû. 2018 22:39 - 12 réponses
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 29 août 2018 - 22:39
Hi

Like the title said.
I want to update the info I have on a page, I execute a thread this thread has a loop with the loop I'm always searching new info, when I get the new info I execute an ExecuteThreadPrincipal with a global procedure just to updated my page.
The query and everything show me it all work (I put every step works fine with a trace) BUT my page wasn't updated, but if I put the exact same global procedure on a button it works good.

So what I'm doing wrong? I know that the two case are really different and I want to updated when I have new info the code of the global procedure it's not that complicated, and the global thread with a loop it's not that difficult too.

Thanks.

--
Best Regards
Jose
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 29 août 2018 - 22:54
Hi

Also if I use the ExecuteMainThread it doesn't execute but if I use my global procedure my code it's executed but doesn't change anything...

Thanks!

--
Best Regards
Jose
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 29 août 2018 - 23:53
Hi

Doing some test I realized that

1. I can't update it with a Thread
2. I can't update it with a Thread and ExecuteMainThread
3. If I use an ExecuteMainThread on my event of the page (end of inisialization) then it works
4. If I use the global procedure it works

So I don't know what to do now...
any ideas?

--
Best Regards
Jose
Membre enregistré
9 messages
Popularité : +2 (2 votes)
Posté le 30 août 2018 - 08:53
HI Jose,
are you working with WinDev Mobile or WebDev?
if it's WebDev, have you already tried to useAJAXExecuteAsynchronous ?

--
Dnl
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 30 août 2018 - 15:38
Hi

Oh! sorry I was wrong with my titled!! it's WebDev.
No I didn't try it, let me see if could work.

Thanks fo the reply!

--
Best Regards
Jose
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 30 août 2018 - 16:26
Hi

I search the info you provide me so there's some things:

1. I need to execute a Thread with a loop that always read for new info, Thread only can be execute it with the server, browser can´t do it.
2. the function you send to me maybe could help but I don't know how to execute it. What I mean? well I have a thread on server with a infinite loop that read for new info (I use SocketRead) when I have the info I need I execute querys to get my new info from the server, then I display everything the query give me to a table on my page.
3. So there's the fuction you get me, it said that it could update the browser when the server procedure have some results, but then again How can I execute it? because I have my thread on server procedure and I don't have any event on browser to execute that function

I really need that thread because it doesn't stop all of the browser (page) and I can use everything, then when I have new info I could see it without stoping the rest of the code.

In the end I don't know how to update it with a Thread or the AJAXExecuteAsynchronous

Thanks for the reply

--
Best Regards
Jose
Posté le 30 août 2018 - 17:13
Hi Jose

first, using a thread as described in a web site is highly unusual and
not really adapted to the way a web site works. Mostly because the START
of the thread would be only when the web site is activated from the
client side and because each new client would create a new thread to
return the same data from the external source.

For the problem as you described it, I would use one of the two
following solutions:

1. create two completely different programs... One, in windev, and
running all the time on my server would replace your secondray thread
and fill my db with the external new data. the second would be my webdev
site with a timer on the page to check if MY db contains new data to
display (with the ajaxexecuteasyncrhonous)

2. Use ONLY my webdev site with my browser timer and
ajaxexeuteasyncrhonrous, and go get the new data from the external
source at that moment only

The choice between 1 and 2 depends on all the details you didn't give us

Best regards

--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Free Video Courses, free WXShowroom.com, open source WXReplication, open
source WXEDM.

More information on http://www.fabriceharari.com




On 8/30/2018 8:26 AM, Jose wrote:
Hi

I search  the info you provide me so there's some things:

1. I need to execute a Thread with a loop that always read for new info,
Thread only can be execute it with the server, browser can´t do it.
2. the function you send to me maybe could help but I don't know how to
execute it. What I mean? well I have a thread on server with a infinite
loop that read for new info (I use SocketRead) when I have the info I
need I execute querys to get my new info from the server, then I display
everything the query give me to a table on my page.
3. So there's the fuction you get me, it said that it could update the
browser when the server procedure have some results, but then again How
can I execute it? because I have my thread on server procedure and I
don't have any event on browser to execute that function

I really need that thread because it doesn't stop all of the browser
(page) and I can use everything, then when I have new info I could see
it without stoping the rest of the code.

In the end I don't know how to update it with a Thread or the
AJAXExecuteAsynchronous

Thanks for the reply

--
Best Regards
Jose
Membre enregistré
9 messages
Popularité : +2 (2 votes)
Posté le 30 août 2018 - 17:44
I'll do some tests to try and help you, because if I remember correctly, Thread do not interact with the pages

meantime, try this
1) creates a global int; for Ex CtrlLoop
2) create a server procedure (ajax) for Ex: LoopCounter

inside something like this:

PROCEDURE LoopCounter ()
   CtrlLoop ++

Multitask (50)
   RESULT CtrlLoop

3) create a browser procedure; for Ex ManagePr

inside

PROCEDURES ManagePr (ResAjax is string)

PrAwb ++

SWITCH ResAjax

CASE "5":
Static1 = "CIAO ITALIA"
OTHER CASE
Static1 = "WHAITING FOR ...."

END

4) Browser side (on load page for ex) put everything together;

FOR ii=1 TO 5
res=AJAXExecuteAsynchronous(ajaxStraightCall,LoopCounter,ManagePr)
END

for 5 times the server procedure will be called and returns a value to the browser procedure.
if the value returned is the right one, the browser procedure does what you ask and it all ends

the progressBar will color itself and you can still use all the objects you have on the page.

--
Dnl
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 30 août 2018 - 18:02
Hi Fabrice

I see... Let me explain even more

I have a site with a infinite loop on a thread in there I have a SocketRead that always wait for some message.
for that SocketRead I have another progam (Windev) always running sending message to PC and Web.
the program send to the Web some info just to be read, when Web see this I know that are new info to be display it on my table of the page
then on those threads I tried to execute "ExecuteMainThread" but it doesn't work, it never going to the actual procedure, if I put the procedure just like that on the thread it execute but never display anything and on code it show some erros if that I want to update controls just use the "ExecuteMainThread" because it could delete info an so on but then again it doesn't work

so there's the problem itself, I could have a timer on my browser to alway check new info but it would be a little anoying always displaying for no reason if there's no new info at all.

it could be new info right away and also it can't be so that's why I send a message to see hey! there's new info update the table!
I'm don't know so much about AJAXExecuteAsynchronous but I will do some test to understand even more that function.

in the end I'm more into the first option just that I don't use the browser timer because I use SocketRead to execute other main threads to display the info of the Query that I execute on those threads too.

Thanks for the ideas

--
Best Regards
Jose
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 30 août 2018 - 18:19
Hi Daniele

I see it!, hmmmmm~ let me build something with this maybe I can get something working


Daniele wrote:
I'll do some tests to try and help you, because if I remember correctly, Thread do not interact with the pages

meantime, try this
1) creates a global int; for Ex CtrlLoop
2) create a server procedure (ajax) for Ex: LoopCounter

inside something like this:

PROCEDURE LoopCounter ()
   CtrlLoop ++

Multitask (50)
   RESULT CtrlLoop

3) create a browser procedure; for Ex ManagePr

inside

PROCEDURES ManagePr (ResAjax is string)

PrAwb ++

SWITCH ResAjax

CASE "5":
Static1 = "CIAO ITALIA"
OTHER CASE
Static1 = "WHAITING FOR ...."

END

4) Browser side (on load page for ex) put everything together;

FOR ii=1 TO 5
res=AJAXExecuteAsynchronous(ajaxStraightCall,LoopCounter,ManagePr)
END

for 5 times the server procedure will be called and returns a value to the browser procedure.
if the value returned is the right one, the browser procedure does what you ask and it all ends

the progressBar will color itself and you can still use all the objects you have on the page.

--
Dnl


--
Best Regards
Jose
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 30 août 2018 - 19:31
Hi everyone

I do some tests so...

I use the example of Daniele I change it a little bit
1. I change the server procedure to a query that I execute to have the new info of my DB and then show it on a second table on my page
2. I change the browser procedure with some tableaddline with a for just to see how it works this tableaddline are for the first table "visible for the user" (also I tought that I use the second table with the query then use a for with it to just add it on the first table "the table visible for the user")

The thing it's that my table with the query never shows info, but the second one actually yes (obvious) because of the tableaddline I put in, I'm trying to add some info on the invisible table just to work with that and put it on the visible one.

I tried change it the mode of the table query Ajax to browser but I don't get any result at all.
I can't link the table with the table of data base because I need really important parameters

I can't execute the query on the browser procedure (obvious) and if I execute the query on the server procedure then it doesn't show anything.

or there's a way I'm not seeing?

--
Best Regards
Jose
Posté le 30 août 2018 - 19:37
Hi

it's not because you have a timer and an ajaxecuteasynchrinous that you
HAVE TO display anything... you just use that process to check IF there
is something new and display it if that's the case...

Here, you are trying to PUSH data from the server to the browser, and
that's NOT how a website works... There is a mechanism able to do that
but it's working only on SOME browser, so it's not useful.

In other words, you are trying to design a web site with a
desktop/windev mentality, and you'll just end up hitting walls doing that.

Best regards


--
Fabrice Harari
International WinDev, WebDev and WinDev mobile Consulting

Free Video Courses, free WXShowroom.com, open source WXReplication, open
source WXEDM.

More information on http://www.fabriceharari.com

On 8/30/2018 10:02 AM, Jose wrote:
Hi Fabrice

I see... Let me explain even more

I have a site with a infinite loop on a thread in there I have a
SocketRead that always wait for some message.
for that SocketRead I have another progam (Windev) always running
sending message to PC and Web.
the program send to the Web some info just to be read, when Web see this
I know that are new info to be display it on my table of the page
then on those threads I tried to execute "ExecuteMainThread" but it
doesn't work, it never going to the actual procedure, if I put the
procedure just like that on the thread it execute but never display
anything and on code it show some erros if that I want to update
controls just use the "ExecuteMainThread" because it could delete info
an so on but then again it doesn't work

so there's the problem itself, I could have a timer on my browser to
alway check new info but it would be a little anoying always displaying
for no reason if there's no new info at all.

it could be new info right away and also it can't be so that's why I
send a message to see hey! there's new info update the table!
I'm don't know so much about AJAXExecuteAsynchronous but I will do some
test to understand even more that function.

in the end I'm more into the first option just that I don't use the
browser timer because I use SocketRead to execute other main threads to
display the info of the Query that I execute on those threads too.

Thanks for the ideas

--
Best Regards
Jose
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 30 août 2018 - 19:46
Hi!

My bad I realized why was doing nothing!

I need to changed the mode to ajaxUpdateControls and then it works! now I will keep doing everything I was thinking and see if work.

Thanks!

--
Best Regards
Jose